|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | RSpec.describe RuboCop::Cop::RSpec::Rails::MinitestAssertions do
|
4 |
| - it 'registers an offense when using `assert_equal`' do |
5 |
| - expect_offense(<<~RUBY) |
6 |
| - assert_equal(a, b) |
7 |
| - ^^^^^^^^^^^^^^^^^^ Use `expect(b).to eq(a)`. |
8 |
| - RUBY |
9 |
| - |
10 |
| - expect_correction(<<~RUBY) |
11 |
| - expect(b).to eq(a) |
12 |
| - RUBY |
13 |
| - end |
| 4 | + context 'with equal assertions' do |
| 5 | + it 'registers an offense when using `assert_equal`' do |
| 6 | + expect_offense(<<~RUBY) |
| 7 | + assert_equal(a, b) |
| 8 | + ^^^^^^^^^^^^^^^^^^ Use `expect(b).to eq(a)`. |
| 9 | + RUBY |
14 | 10 |
|
15 |
| - it 'registers an offense when using `assert_equal` with no parentheses' do |
16 |
| - expect_offense(<<~RUBY) |
17 |
| - assert_equal a, b |
18 |
| - ^^^^^^^^^^^^^^^^^ Use `expect(b).to eq(a)`. |
19 |
| - RUBY |
| 11 | + expect_correction(<<~RUBY) |
| 12 | + expect(b).to eq(a) |
| 13 | + RUBY |
| 14 | + end |
20 | 15 |
|
21 |
| - expect_correction(<<~RUBY) |
22 |
| - expect(b).to eq(a) |
23 |
| - RUBY |
24 |
| - end |
| 16 | + it 'registers an offense when using `assert_equal` with no parentheses' do |
| 17 | + expect_offense(<<~RUBY) |
| 18 | + assert_equal a, b |
| 19 | + ^^^^^^^^^^^^^^^^^ Use `expect(b).to eq(a)`. |
| 20 | + RUBY |
25 | 21 |
|
26 |
| - it 'registers an offense when using `assert_equal` with failure message' do |
27 |
| - expect_offense(<<~RUBY) |
28 |
| - assert_equal a, b, "must be equal" |
29 |
| - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(b).to(eq(a), "must be equal")`. |
30 |
| - RUBY |
| 22 | + expect_correction(<<~RUBY) |
| 23 | + expect(b).to eq(a) |
| 24 | + RUBY |
| 25 | + end |
31 | 26 |
|
32 |
| - expect_correction(<<~RUBY) |
33 |
| - expect(b).to(eq(a), "must be equal") |
34 |
| - RUBY |
35 |
| - end |
| 27 | + it 'registers an offense when using `assert_equal` with failure message' do |
| 28 | + expect_offense(<<~RUBY) |
| 29 | + assert_equal a, b, "must be equal" |
| 30 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(b).to(eq(a), "must be equal")`. |
| 31 | + RUBY |
36 | 32 |
|
37 |
| - it 'registers an offense when using `assert_equal` with ' \ |
38 |
| - 'multi-line arguments' do |
39 |
| - expect_offense(<<~RUBY) |
40 |
| - assert_equal(a, |
41 |
| - ^^^^^^^^^^^^^^^ Use `expect(b).to(eq(a), "must be equal")`. |
42 |
| - b, |
43 |
| - "must be equal") |
44 |
| - RUBY |
45 |
| - |
46 |
| - expect_correction(<<~RUBY) |
47 |
| - expect(b).to(eq(a), "must be equal") |
48 |
| - RUBY |
49 |
| - end |
| 33 | + expect_correction(<<~RUBY) |
| 34 | + expect(b).to(eq(a), "must be equal") |
| 35 | + RUBY |
| 36 | + end |
50 | 37 |
|
51 |
| - it 'registers an offense when using `refute_equal`' do |
52 |
| - expect_offense(<<~RUBY) |
53 |
| - refute_equal a, b |
54 |
| - ^^^^^^^^^^^^^^^^^ Use `expect(b).not_to eq(a)`. |
55 |
| - RUBY |
| 38 | + it 'registers an offense when using `assert_equal` with ' \ |
| 39 | + 'multi-line arguments' do |
| 40 | + expect_offense(<<~RUBY) |
| 41 | + assert_equal(a, |
| 42 | + ^^^^^^^^^^^^^^^ Use `expect(b).to(eq(a), "must be equal")`. |
| 43 | + b, |
| 44 | + "must be equal") |
| 45 | + RUBY |
56 | 46 |
|
57 |
| - expect_correction(<<~RUBY) |
58 |
| - expect(b).not_to eq(a) |
59 |
| - RUBY |
60 |
| - end |
| 47 | + expect_correction(<<~RUBY) |
| 48 | + expect(b).to(eq(a), "must be equal") |
| 49 | + RUBY |
| 50 | + end |
61 | 51 |
|
62 |
| - it 'does not register an offense when using `expect(b).to eq(a)`' do |
63 |
| - expect_no_offenses(<<~RUBY) |
64 |
| - expect(b).to eq(a) |
65 |
| - RUBY |
| 52 | + it 'registers an offense when using `refute_equal`' do |
| 53 | + expect_offense(<<~RUBY) |
| 54 | + refute_equal a, b |
| 55 | + ^^^^^^^^^^^^^^^^^ Use `expect(b).not_to eq(a)`. |
| 56 | + RUBY |
| 57 | + |
| 58 | + expect_correction(<<~RUBY) |
| 59 | + expect(b).not_to eq(a) |
| 60 | + RUBY |
| 61 | + end |
| 62 | + |
| 63 | + it 'does not register an offense when using `expect(b).to eq(a)`' do |
| 64 | + expect_no_offenses(<<~RUBY) |
| 65 | + expect(b).to eq(a) |
| 66 | + RUBY |
| 67 | + end |
| 68 | + |
| 69 | + it 'does not register an offense when using `expect(b).not_to eq(a)`' do |
| 70 | + expect_no_offenses(<<~RUBY) |
| 71 | + expect(b).not_to eq(a) |
| 72 | + RUBY |
| 73 | + end |
66 | 74 | end
|
67 | 75 |
|
68 |
| - it 'does not register an offense when using `expect(b).not_to eq(a)`' do |
69 |
| - expect_no_offenses(<<~RUBY) |
70 |
| - expect(b).not_to eq(a) |
71 |
| - RUBY |
| 76 | + context 'with nil assertions' do |
| 77 | + it 'registers an offense when using `assert_nil`' do |
| 78 | + expect_offense(<<~RUBY) |
| 79 | + assert_nil(a) |
| 80 | + ^^^^^^^^^^^^^ Use `expect(a).to eq(nil)`. |
| 81 | + RUBY |
| 82 | + |
| 83 | + expect_correction(<<~RUBY) |
| 84 | + expect(a).to eq(nil) |
| 85 | + RUBY |
| 86 | + end |
| 87 | + |
| 88 | + it 'registers an offense when using `assert_nil` with no parentheses' do |
| 89 | + expect_offense(<<~RUBY) |
| 90 | + assert_nil a |
| 91 | + ^^^^^^^^^^^^ Use `expect(a).to eq(nil)`. |
| 92 | + RUBY |
| 93 | + |
| 94 | + expect_correction(<<~RUBY) |
| 95 | + expect(a).to eq(nil) |
| 96 | + RUBY |
| 97 | + end |
| 98 | + |
| 99 | + it 'registers an offense when using `assert_nil` with failure message' do |
| 100 | + expect_offense(<<~RUBY) |
| 101 | + assert_nil a, "must be nil" |
| 102 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(a).to(eq(nil), "must be nil")`. |
| 103 | + RUBY |
| 104 | + |
| 105 | + expect_correction(<<~RUBY) |
| 106 | + expect(a).to(eq(nil), "must be nil") |
| 107 | + RUBY |
| 108 | + end |
| 109 | + |
| 110 | + it 'registers an offense when using `assert_nil` with ' \ |
| 111 | + 'multi-line arguments' do |
| 112 | + expect_offense(<<~RUBY) |
| 113 | + assert_nil(a, |
| 114 | + ^^^^^^^^^^^^^ Use `expect(a).to(eq(nil), "must be nil")`. |
| 115 | + "must be nil") |
| 116 | + RUBY |
| 117 | + |
| 118 | + expect_correction(<<~RUBY) |
| 119 | + expect(a).to(eq(nil), "must be nil") |
| 120 | + RUBY |
| 121 | + end |
| 122 | + |
| 123 | + it 'registers an offense when using `refute_nil`' do |
| 124 | + expect_offense(<<~RUBY) |
| 125 | + refute_nil a |
| 126 | + ^^^^^^^^^^^^ Use `expect(a).not_to eq(nil)`. |
| 127 | + RUBY |
| 128 | + |
| 129 | + expect_correction(<<~RUBY) |
| 130 | + expect(a).not_to eq(nil) |
| 131 | + RUBY |
| 132 | + end |
| 133 | + |
| 134 | + it 'does not register an offense when using `expect(a).to eq(nil)`' do |
| 135 | + expect_no_offenses(<<~RUBY) |
| 136 | + expect(a).to eq(nil) |
| 137 | + RUBY |
| 138 | + end |
| 139 | + |
| 140 | + it 'does not register an offense when using `expect(a).not_to eq(nil)`' do |
| 141 | + expect_no_offenses(<<~RUBY) |
| 142 | + expect(a).not_to eq(nil) |
| 143 | + RUBY |
| 144 | + end |
72 | 145 | end
|
73 | 146 | end
|
0 commit comments