Skip to content

Commit 1130597

Browse files
committed
fix: vary responses used in tests as http status will not always be :ok
1 parent 3e03e55 commit 1130597

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

spec/rubocop/cop/rspec_rails/minitest_assertions_spec.rb

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -951,23 +951,34 @@
951951
context 'with response assertions' do
952952
it 'registers an offense when using `assert_response`' do
953953
expect_offense(<<~RUBY)
954-
assert_response :ok
955-
^^^^^^^^^^^^^^^^^^^ Use `expect(response).to have_http_status(:ok)`.
954+
assert_response :redirect
955+
^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to have_http_status(:redirect)`.
956956
RUBY
957957

958958
expect_correction(<<~RUBY)
959-
expect(response).to have_http_status(:ok)
959+
expect(response).to have_http_status(:redirect)
960+
RUBY
961+
end
962+
963+
it 'registers an offense when using `assert_response` with a number' do
964+
expect_offense(<<~RUBY)
965+
assert_response 200
966+
^^^^^^^^^^^^^^^^^^^ Use `expect(response).to have_http_status(200)`.
967+
RUBY
968+
969+
expect_correction(<<~RUBY)
970+
expect(response).to have_http_status(200)
960971
RUBY
961972
end
962973

963974
it 'registers an offense when using `assert_response` with parentheses' do
964975
expect_offense(<<~RUBY)
965-
assert_response(:ok)
966-
^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to have_http_status(:ok)`.
976+
assert_response(:success)
977+
^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to have_http_status(:success)`.
967978
RUBY
968979

969980
expect_correction(<<~RUBY)
970-
expect(response).to have_http_status(:ok)
981+
expect(response).to have_http_status(:success)
971982
RUBY
972983
end
973984

@@ -1011,7 +1022,7 @@
10111022
it 'does not register an offense when using ' \
10121023
'`expect(response).to have_http_status`' do
10131024
expect_no_offenses(<<~RUBY)
1014-
expect(response).to have_http_status(:ok)
1025+
expect(response).to have_http_status(:success)
10151026
RUBY
10161027
end
10171028

0 commit comments

Comments
 (0)