File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Master (Unreleased)
4
4
5
+ * Fix a regression in ` RSpec/ExpectChange ` flagging chained method calls. ([ @pirj ] [ ] )
6
+
5
7
## 2.11.0 (2022-05-18)
6
8
7
9
* Drop Ruby 2.5 support. ([ @ydah ] [ ] )
Original file line number Diff line number Diff line change @@ -47,7 +47,13 @@ class ExpectChange < Base
47
47
(block
48
48
(send nil? :change)
49
49
(args)
50
- (send $_ $_)
50
+ (send
51
+ ${
52
+ (send nil? _) # change { user.name }
53
+ const # change { User.count }
54
+ }
55
+ $_
56
+ )
51
57
)
52
58
PATTERN
53
59
Original file line number Diff line number Diff line change 86
86
RUBY
87
87
end
88
88
89
- it 'flags chained method calls ' do
89
+ it 'flags a method call on an object ' do
90
90
expect_offense ( <<-RUBY )
91
91
it do
92
- expect { file.upload! }.to change { user.uploads.count }.by(1)
93
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `change(user.uploads, :count)`.
92
+ expect { run }.to change { user.name }.to('Jack')
93
+ ^^^^^^^^^^^^^^^^^^^^ Prefer `change(user, :name)`.
94
+ end
95
+ RUBY
96
+
97
+ expect_correction ( <<-RUBY )
98
+ it do
99
+ expect { run }.to change(user, :name).to('Jack')
100
+ end
101
+ RUBY
102
+ end
103
+
104
+ it 'ignores multiple chained method calls' do
105
+ expect_no_offenses ( <<-RUBY )
106
+ it do
107
+ expect { run }.to change { user.reload.name }
108
+ end
109
+ RUBY
110
+ end
111
+
112
+ it 'ignores a variable/method' do
113
+ expect_no_offenses ( <<-RUBY )
114
+ it do
115
+ expect { run }.to change { results }.to([])
94
116
end
95
117
RUBY
96
118
end
You can’t perform that action at this time.
0 commit comments