Skip to content

Commit 7f71a6f

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

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

spec/rubocop/cop/rspec_rails/minitest_assertions_spec.rb

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -951,48 +951,59 @@
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 302
966+
^^^^^^^^^^^^^^^^^^^ Use `expect(response).to have_http_status(302)`.
967+
RUBY
968+
969+
expect_correction(<<~RUBY)
970+
expect(response).to have_http_status(302)
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

974985
it 'registers an offense when using `assert_response` with ' \
975986
'failure message' do
976987
expect_offense(<<~RUBY)
977-
assert_response :ok, "expected OK status"
978-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to(have_http_status(:ok), "expected OK status")`.
988+
assert_response :success, "expected success status"
989+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to(have_http_status(:success), "expected success status")`.
979990
RUBY
980991

981992
expect_correction(<<~RUBY)
982-
expect(response).to(have_http_status(:ok), "expected OK status")
993+
expect(response).to(have_http_status(:success), "expected success status")
983994
RUBY
984995
end
985996

986997
it 'registers an offense when using `assert_response` with ' \
987998
'multi-line arguments' do
988999
expect_offense(<<~RUBY)
989-
assert_response(:ok,
990-
^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to(have_http_status(:ok), "expected OK status")`.
991-
"expected OK status")
1000+
assert_response(:redirect,
1001+
^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to(have_http_status(:redirect), "expected redirect status")`.
1002+
"expected redirect status")
9921003
RUBY
9931004

9941005
expect_correction(<<~RUBY)
995-
expect(response).to(have_http_status(:ok), "expected OK status")
1006+
expect(response).to(have_http_status(:redirect), "expected redirect status")
9961007
RUBY
9971008
end
9981009

@@ -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)