|
947 | 947 | RUBY |
948 | 948 | end |
949 | 949 | end |
| 950 | + |
| 951 | + context 'with response assertions' do |
| 952 | + it 'registers an offense when using `assert_response`' do |
| 953 | + expect_offense(<<~RUBY) |
| 954 | + assert_response :ok |
| 955 | + ^^^^^^^^^^^^^^^^^^^ Use `expect(response).to have_http_status(:ok)`. |
| 956 | + RUBY |
| 957 | + |
| 958 | + expect_correction(<<~RUBY) |
| 959 | + expect(response).to have_http_status(:ok) |
| 960 | + RUBY |
| 961 | + end |
| 962 | + |
| 963 | + it 'registers an offense when using `assert_response` with parentheses' do |
| 964 | + expect_offense(<<~RUBY) |
| 965 | + assert_response(:ok) |
| 966 | + ^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to have_http_status(:ok)`. |
| 967 | + RUBY |
| 968 | + |
| 969 | + expect_correction(<<~RUBY) |
| 970 | + expect(response).to have_http_status(:ok) |
| 971 | + RUBY |
| 972 | + end |
| 973 | + |
| 974 | + it 'registers an offense when using `assert_response` with ' \ |
| 975 | + 'failure message' do |
| 976 | + expect_offense(<<~RUBY) |
| 977 | + assert_response :ok, "expected OK status" |
| 978 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to(have_http_status(:ok), "expected OK status")`. |
| 979 | + RUBY |
| 980 | + |
| 981 | + expect_correction(<<~RUBY) |
| 982 | + expect(response).to(have_http_status(:ok), "expected OK status") |
| 983 | + RUBY |
| 984 | + end |
| 985 | + |
| 986 | + it 'registers an offense when using `assert_response` with ' \ |
| 987 | + 'multi-line arguments' do |
| 988 | + expect_offense(<<~RUBY) |
| 989 | + assert_response(:ok, |
| 990 | + ^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to(have_http_status(:ok), "expected OK status")`. |
| 991 | + "expected OK status") |
| 992 | + RUBY |
| 993 | + |
| 994 | + expect_correction(<<~RUBY) |
| 995 | + expect(response).to(have_http_status(:ok), "expected OK status") |
| 996 | + RUBY |
| 997 | + end |
| 998 | + |
| 999 | + it 'registers an offense when using `assert_response` with ' \ |
| 1000 | + 'numeric status' do |
| 1001 | + expect_offense(<<~RUBY) |
| 1002 | + assert_response 200 |
| 1003 | + ^^^^^^^^^^^^^^^^^^^ Use `expect(response).to have_http_status(200)`. |
| 1004 | + RUBY |
| 1005 | + |
| 1006 | + expect_correction(<<~RUBY) |
| 1007 | + expect(response).to have_http_status(200) |
| 1008 | + RUBY |
| 1009 | + end |
| 1010 | + |
| 1011 | + it 'does not register an offense when using ' \ |
| 1012 | + '`expect(response).to have_http_status`' do |
| 1013 | + expect_no_offenses(<<~RUBY) |
| 1014 | + expect(response).to have_http_status(:ok) |
| 1015 | + RUBY |
| 1016 | + end |
| 1017 | + |
| 1018 | + it 'does not register an offense when using ' \ |
| 1019 | + '`expect(response).to have_http_status` with numeric status' do |
| 1020 | + expect_no_offenses(<<~RUBY) |
| 1021 | + expect(response).to have_http_status(200) |
| 1022 | + RUBY |
| 1023 | + end |
| 1024 | + end |
950 | 1025 | end |
0 commit comments