Class: Reins::Spec::Matchers::RedirectTo

Inherits:
Object
  • Object
show all
Defined in:
lib/reins/spec/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ RedirectTo

Returns a new instance of RedirectTo.



36
37
38
# File 'lib/reins/spec/matchers.rb', line 36

def initialize(url)
  @expected_url = url
end

Instance Method Details

#failure_messageObject



47
48
49
50
# File 'lib/reins/spec/matchers.rb', line 47

def failure_message
  "expected a 3xx redirect to #{@expected_url.inspect}, " \
    "got status #{@actual_status} location #{@actual_location.inspect}"
end

#matches?(response) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/reins/spec/matchers.rb', line 40

def matches?(response)
  @actual_status = response.status
  location_header = response.headers["Location"] || response.headers["location"]
  @actual_location = location_header
  (300..399).cover?(@actual_status) && @actual_location == @expected_url
end