Class: RSpec::Http::ResponseCodeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/http/response_code_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_code) ⇒ ResponseCodeMatcher



4
5
6
# File 'lib/rspec/http/response_code_matcher.rb', line 4

def initialize(expected_code)
  @expected_code = expected_code
end

Instance Method Details

#common_messageObject



25
26
27
28
29
30
31
# File 'lib/rspec/http/response_code_matcher.rb', line 25

def common_message
  message = "have a response code of #{@expected_code}, but got #{@target.status}"
  if @target.status == 302 || @target.status == 201
    message += " with a location of #{@target['Location'] || @target['location']}" 
  end
  message
end

#descriptionObject



13
14
15
# File 'lib/rspec/http/response_code_matcher.rb', line 13

def description
  "Response code should be #{@expected_code}"
end

#failure_messageObject



17
18
19
# File 'lib/rspec/http/response_code_matcher.rb', line 17

def failure_message
  "Expected #{@target} to #{common_message}"
end

#failure_message_when_negatedObject



21
22
23
# File 'lib/rspec/http/response_code_matcher.rb', line 21

def failure_message_when_negated
  "Expected #{@target} to not #{common_message}"
end

#matches?(target) ⇒ Boolean



8
9
10
11
# File 'lib/rspec/http/response_code_matcher.rb', line 8

def matches?(target)
  @target = target
  @target.status == @expected_code
end