|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | RSpec.describe RuboCop::Cop::RSpec::RepeatedSubjectCall do |
4 | | - it 'registers an offense for a singular block' do |
| 4 | + it 'registers an offense when a singular block' do |
5 | 5 | expect_offense(<<-RUBY) |
6 | 6 | RSpec.describe Foo do |
7 | 7 | it do |
|
13 | 13 | RUBY |
14 | 14 | end |
15 | 15 |
|
16 | | - it 'registers an offense for repeated blocks' do |
| 16 | + it 'registers an offense when repeated blocks' do |
17 | 17 | expect_offense(<<-RUBY) |
18 | 18 | RSpec.describe Foo do |
19 | 19 | it do |
|
25 | 25 | RUBY |
26 | 26 | end |
27 | 27 |
|
28 | | - it 'registers an offense for nested blocks' do |
| 28 | + it 'registers an offense when nested blocks' do |
29 | 29 | expect_offense(<<-RUBY) |
30 | 30 | RSpec.describe Foo do |
31 | 31 | it do |
|
39 | 39 | RUBY |
40 | 40 | end |
41 | 41 |
|
42 | | - it 'registers an offense for custom subjects' do |
| 42 | + it 'registers an offense when custom subjects' do |
43 | 43 | expect_offense(<<-RUBY) |
44 | 44 | RSpec.describe Foo do |
45 | 45 | subject(:bar) { do_something } |
|
53 | 53 | RUBY |
54 | 54 | end |
55 | 55 |
|
56 | | - it 'registers no offenses for no block' do |
| 56 | + it 'does not register an offense when no block' do |
57 | 57 | expect_no_offenses(<<~RUBY) |
58 | 58 | RSpec.describe Foo do |
59 | 59 | it do |
|
64 | 64 | RUBY |
65 | 65 | end |
66 | 66 |
|
67 | | - it 'registers no offenses for block first' do |
| 67 | + it 'does not register an offense when block first' do |
68 | 68 | expect_no_offenses(<<~RUBY) |
69 | 69 | RSpec.describe Foo do |
70 | 70 | it do |
|
75 | 75 | RUBY |
76 | 76 | end |
77 | 77 |
|
78 | | - it 'registers no offenses for different subjects' do |
| 78 | + it 'does not register an offense when different subjects' do |
79 | 79 | expect_no_offenses(<<-RUBY) |
80 | 80 | RSpec.describe Foo do |
81 | 81 | subject { do_something_else } |
|
89 | 89 | RUBY |
90 | 90 | end |
91 | 91 |
|
92 | | - it 'registers no offenses for multiple no description it blocks' do |
| 92 | + it 'does not register an offense when multiple no description it blocks' do |
93 | 93 | expect_no_offenses(<<-RUBY) |
94 | 94 | RSpec.describe Foo do |
95 | 95 | it do |
|
103 | 103 | RUBY |
104 | 104 | end |
105 | 105 |
|
106 | | - it 'registers no offenses for `subject.method_call`' do |
| 106 | + it 'does not register an offense when `subject.method_call`' do |
107 | 107 | expect_no_offenses(<<~RUBY) |
108 | 108 | RSpec.describe Foo do |
109 | 109 | it do |
|
113 | 113 | end |
114 | 114 | RUBY |
115 | 115 | end |
| 116 | + |
| 117 | + it 'does not register an offense when `subject` with not expectation' do |
| 118 | + expect_no_offenses(<<~RUBY) |
| 119 | + RSpec.describe Foo do |
| 120 | + it do |
| 121 | + allow(Foo).to receive(:bar).and_return(subject) |
| 122 | + allow(Foo).to receive(:bar) { subject } |
| 123 | + end |
| 124 | + end |
| 125 | + RUBY |
| 126 | + end |
| 127 | + |
| 128 | + it 'does not register an offense when `subject` not inside example' do |
| 129 | + expect_no_offenses(<<~RUBY) |
| 130 | + RSpec.describe Foo do |
| 131 | + subject { do_something } |
| 132 | +
|
| 133 | + it do |
| 134 | + expect { subject }.to change { Foo.count } |
| 135 | + end |
| 136 | + end |
| 137 | + RUBY |
| 138 | + end |
| 139 | + |
| 140 | + it 'does not register an offense when `subject` is not inside describe' do |
| 141 | + expect_no_offenses(<<~RUBY) |
| 142 | + Foo.subject(:bar) |
| 143 | + subject(:bar) |
| 144 | + subject |
| 145 | + RUBY |
| 146 | + end |
116 | 147 | end |
0 commit comments