|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe RuboCop::Cop::RSpecRails::HttpStatusNameConsistency, :config do |
| 4 | + context 'when Rack is older than 3.1' do |
| 5 | + let(:gem_versions) { { 'rack' => '3.0.0' } } |
| 6 | + |
| 7 | + it 'does nothing when using :unprocessable_entity' do |
| 8 | + expect_no_offenses(<<~RUBY) |
| 9 | + it { is_expected.to have_http_status :unprocessable_entity } |
| 10 | + RUBY |
| 11 | + end |
| 12 | + |
| 13 | + it 'does nothing when using :payload_too_large' do |
| 14 | + expect_no_offenses(<<~RUBY) |
| 15 | + it { is_expected.to have_http_status :payload_too_large } |
| 16 | + RUBY |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + context 'when Rack is 3.1 or later' do |
| 21 | + let(:gem_versions) { { 'rack' => '3.1.0' } } |
| 22 | + |
| 23 | + it 'registers an offense when using :unprocessable_entity' do |
| 24 | + expect_offense(<<~RUBY) |
| 25 | + it { is_expected.to have_http_status :unprocessable_entity } |
| 26 | + ^^^^^^^^^^^^^^^^^^^^^ Use `Prefer `:unprocessable_content` over `:unprocessable_entity`. |
| 27 | + RUBY |
| 28 | + |
| 29 | + expect_correction(<<~RUBY) |
| 30 | + it { is_expected.to have_http_status :unprocessable_content } |
| 31 | + RUBY |
| 32 | + end |
| 33 | + |
| 34 | + it 'does not register an offense when using :unprocessable_content' do |
| 35 | + expect_no_offenses(<<~RUBY) |
| 36 | + it { is_expected.to have_http_status :unprocessable_content } |
| 37 | + RUBY |
| 38 | + end |
| 39 | + |
| 40 | + it 'registers an offense when using :payload_too_large' do |
| 41 | + expect_offense(<<~RUBY) |
| 42 | + it { is_expected.to have_http_status :payload_too_large } |
| 43 | + ^^^^^^^^^^^^^^^^^^ Use `Prefer `:content_too_large` over `:payload_too_large`. |
| 44 | + RUBY |
| 45 | + |
| 46 | + expect_correction(<<~RUBY) |
| 47 | + it { is_expected.to have_http_status :content_too_large } |
| 48 | + RUBY |
| 49 | + end |
| 50 | + |
| 51 | + it 'does not register an offense when using :content_too_large' do |
| 52 | + expect_no_offenses(<<~RUBY) |
| 53 | + it { is_expected.to have_http_status :content_too_large } |
| 54 | + RUBY |
| 55 | + end |
| 56 | + |
| 57 | + it 'does nothing when using numeric value' do |
| 58 | + expect_no_offenses(<<~RUBY) |
| 59 | + it { is_expected.to have_http_status 200 } |
| 60 | + RUBY |
| 61 | + end |
| 62 | + |
| 63 | + it 'does nothing when using string value' do |
| 64 | + expect_no_offenses(<<~RUBY) |
| 65 | + it { is_expected.to have_http_status "200" } |
| 66 | + RUBY |
| 67 | + end |
| 68 | + end |
| 69 | +end |
0 commit comments