Skip to content

Commit 80afb90

Browse files
wbreezeJonRowe
authored andcommitted
Remove the version check in have_http_status (#1965)
The successful?, server_error?, and not_found? methods for ActionDispatch::TestResponse have existed in Rails for a very long time. It isn't necessary to check for Rails 5.2 or greater in order to use them.
1 parent 1e3e9a5 commit 80afb90

File tree

2 files changed

+48
-60
lines changed

2 files changed

+48
-60
lines changed

lib/rspec/rails/matchers/have_http_status.rb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -289,20 +289,11 @@ def failure_message_when_negated
289289

290290
protected
291291

292-
if 5 < ::Rails::VERSION::MAJOR ||
293-
(::Rails::VERSION::MAJOR == 5 && 2 <= ::Rails::VERSION::MINOR)
294-
RESPONSE_METHODS = {
295-
:success => 'successful',
296-
:error => 'server_error',
297-
:missing => 'not_found'
298-
}.freeze
299-
else
300-
RESPONSE_METHODS = {
301-
:successful => 'success',
302-
:server_error => 'error',
303-
:not_found => 'missing'
304-
}.freeze
305-
end
292+
RESPONSE_METHODS = {
293+
:success => 'successful',
294+
:error => 'server_error',
295+
:missing => 'not_found'
296+
}.freeze
306297

307298
def check_expected_status(test_response, expected)
308299
test_response.send(

spec/rspec/rails/matchers/have_http_status_spec.rb

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -435,65 +435,62 @@ def create_response(opts = {})
435435
end
436436
end
437437

438-
if 5 < Rails::VERSION::MAJOR ||
439-
(Rails::VERSION::MAJOR == 5 && 2 <= Rails::VERSION::MINOR)
440-
shared_examples_for "does not use deprecated methods for Rails 5.2+" do
441-
it "does not use deprecated method for Rails >= 5.2" do
442-
previous_stderr = $stderr
443-
begin
444-
splitter = RSpec::Support::StdErrSplitter.new(previous_stderr)
445-
$stderr = splitter
446-
response = ::ActionDispatch::Response.new(code).tap {|x|
447-
x.request = ActionDispatch::Request.new({})
448-
}
449-
expect( matcher.matches?(response) ).to be(true)
450-
expect(splitter.has_output?).to be false
451-
ensure
452-
$stderr = previous_stderr
453-
end
438+
shared_examples_for "does not use deprecated methods for Rails 5.2+" do
439+
it "does not use deprecated method for Rails >= 5.2" do
440+
previous_stderr = $stderr
441+
begin
442+
splitter = RSpec::Support::StdErrSplitter.new(previous_stderr)
443+
$stderr = splitter
444+
response = ::ActionDispatch::Response.new(code).tap {|x|
445+
x.request = ActionDispatch::Request.new({})
446+
}
447+
expect( matcher.matches?(response) ).to be(true)
448+
expect(splitter.has_output?).to be false
449+
ensure
450+
$stderr = previous_stderr
454451
end
455452
end
453+
end
456454

457-
context 'http status :missing' do
458-
it_behaves_like "does not use deprecated methods for Rails 5.2+" do
459-
subject(:matcher) { have_http_status(:missing) }
460-
let(:code) { 404 }
461-
end
455+
context 'http status :missing' do
456+
it_behaves_like "does not use deprecated methods for Rails 5.2+" do
457+
subject(:matcher) { have_http_status(:missing) }
458+
let(:code) { 404 }
462459
end
460+
end
463461

464-
context 'http status :success' do
465-
it_behaves_like "does not use deprecated methods for Rails 5.2+" do
466-
subject(:matcher) { have_http_status(:success) }
467-
let(:code) { 222 }
468-
end
462+
context 'http status :success' do
463+
it_behaves_like "does not use deprecated methods for Rails 5.2+" do
464+
subject(:matcher) { have_http_status(:success) }
465+
let(:code) { 222 }
469466
end
467+
end
470468

471-
context 'http status :error' do
472-
it_behaves_like "does not use deprecated methods for Rails 5.2+" do
473-
subject(:matcher) { have_http_status(:error) }
474-
let(:code) { 555 }
475-
end
469+
context 'http status :error' do
470+
it_behaves_like "does not use deprecated methods for Rails 5.2+" do
471+
subject(:matcher) { have_http_status(:error) }
472+
let(:code) { 555 }
476473
end
474+
end
477475

478-
context 'http status :not_found' do
479-
it_behaves_like "supports different response instances" do
480-
subject(:matcher) { have_http_status(:not_found) }
481-
let(:code) { 404 }
482-
end
476+
context 'http status :not_found' do
477+
it_behaves_like "supports different response instances" do
478+
subject(:matcher) { have_http_status(:not_found) }
479+
let(:code) { 404 }
483480
end
481+
end
484482

485-
context 'http status :successful' do
486-
it_behaves_like "supports different response instances" do
487-
subject(:matcher) { have_http_status(:successful) }
488-
let(:code) { 222 }
489-
end
483+
context 'http status :successful' do
484+
it_behaves_like "supports different response instances" do
485+
subject(:matcher) { have_http_status(:successful) }
486+
let(:code) { 222 }
490487
end
488+
end
491489

492-
context 'http status :server_error' do
493-
it_behaves_like "supports different response instances" do
494-
subject(:matcher) { have_http_status(:server_error) }
495-
let(:code) { 555 }
496-
end
490+
context 'http status :server_error' do
491+
it_behaves_like "supports different response instances" do
492+
subject(:matcher) { have_http_status(:server_error) }
493+
let(:code) { 555 }
497494
end
498495
end
499496
end

0 commit comments

Comments
 (0)