Skip to content

Commit 6e252ee

Browse files
author
Sam Phippen
committed
Fixup response code handling in have_http_status.
This now consistently calls `.to_i` on response codes, which ensures they're always an integer (accross rails versions). Additionally I replaced a number of `333` codes with `308`s. The reasoning for this is that rack no longer accepts non-spec 3xx codes in it's `redirect?` methods, which breaks our tests.
1 parent 4e73e71 commit 6e252ee

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lib/rspec/rails/matchers/have_http_status.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def initialize(code)
8484
# @return [Boolean] `true` if the numeric code matched the `response` code
8585
def matches?(response)
8686
test_response = as_test_response(response)
87-
@actual = test_response.response_code
87+
@actual = test_response.response_code.to_i
8888
expected == @actual
8989
rescue TypeError => _ignored
9090
@invalid_response = response

spec/rspec/rails/matchers/have_http_status_spec.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,12 @@ def create_response(opts = {})
382382
it_behaves_like "supports different response instances" do
383383
subject(:matcher) { have_redirect_status }
384384

385-
let(:code) { 333 }
385+
let(:code) { 308 }
386386
end
387387

388388
describe "matching a response" do
389389
it "returns true for a response with a 3xx status code" do
390-
any_3xx_code = 333
390+
any_3xx_code = 308
391391
response = create_response(:status => any_3xx_code)
392392

393393
expect( have_redirect_status.matches?(response) ).to be(true)
@@ -416,12 +416,12 @@ def create_response(opts = {})
416416
end
417417

418418
it "has a negated failure message reporting the expected and actual status codes" do
419-
any_3xx_code = 333
419+
any_3xx_code = 308
420420
response = create_response(:status => any_3xx_code)
421421

422422
expect{ have_redirect_status.matches? response }.
423423
to change(have_redirect_status, :failure_message_when_negated).
424-
to(/not to have a redirect status code \(3xx\) but it was 333/)
424+
to(/not to have a redirect status code \(3xx\) but it was 308/)
425425
end
426426
end
427427

@@ -430,5 +430,4 @@ def create_response(opts = {})
430430
expect{ have_http_status(nil) }.to raise_error ArgumentError
431431
end
432432
end
433-
434433
end

0 commit comments

Comments
 (0)