module RSpec::WebserviceMatchers::RedirectHelpers
Public Instance Methods
kind_for(status)
click to toggle source
# File lib/rspec/webservice_matchers/redirect_helpers.rb, line 58 def kind_for(status) { 301 => 'permanent', 302 => 'temporary', 307 => 'temporary' }[status] end
locations_match?(expected, actual)
click to toggle source
# File lib/rspec/webservice_matchers/redirect_helpers.rb, line 35 def locations_match?(expected, actual) actual =~ %r{#{expected}/?} end
permanent_redirect?(status)
click to toggle source
# File lib/rspec/webservice_matchers/redirect_helpers.rb, line 54 def permanent_redirect?(status) status == 301 end
redirect?(status, kind: nil)
click to toggle source
# File lib/rspec/webservice_matchers/redirect_helpers.rb, line 39 def redirect?(status, kind: nil) case kind when :permanent permanent_redirect?(status) when :temporary temp_redirect?(status) else temp_redirect?(status) || permanent_redirect?(status) end end
redirect_failure_message(exception, status, actual_location, kind)
click to toggle source
# File lib/rspec/webservice_matchers/redirect_helpers.rb, line 8 def redirect_failure_message(exception, status, actual_location, kind) return WebTest::Util.error_message(exception) if exception errors = [] if redirect? status unless redirect? status, kind: kind errors << "received a #{kind_for(status)} redirect" end unless locations_match? expected, actual_location errors << "received location #{actual_location}" end else errors << "not a redirect: received status #{status}" end WebTest::Util.error_message(errors) end
redirect_result(url_or_domain_name)
click to toggle source
# File lib/rspec/webservice_matchers/redirect_helpers.rb, line 30 def redirect_result(url_or_domain_name) status, headers = WebTest::Util.head(url_or_domain_name) [status, headers['location']] end
redirects_correctly?(status, actual_loc, expected_loc, kind)
click to toggle source
# File lib/rspec/webservice_matchers/redirect_helpers.rb, line 26 def redirects_correctly?(status, actual_loc, expected_loc, kind) redirect?(status, kind: kind) && locations_match?(expected_loc, actual_loc) end
temp_redirect?(status)
click to toggle source
# File lib/rspec/webservice_matchers/redirect_helpers.rb, line 50 def temp_redirect?(status) [302, 307].include?(status) end