File tree 3 files changed +21
-0
lines changed
3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Master (Unreleased)
4
4
5
+ - Add explanation why ` RSpec/ExpectChange ` autocorrection is unsafe. ([ @lovro-bikic ] )
5
6
- Fix false positive in ` RSpec/Pending ` , where it would mark the default block ` it ` as an offense. ([ @bquorning ] )
6
7
7
8
## 3.5.0 (2025-02-16)
Original file line number Diff line number Diff line change @@ -2130,6 +2130,17 @@ or passing a block that reads the attribute value.
2130
2130
2131
2131
This cop can be configured using the `EnforcedStyle` option.
2132
2132
2133
+ [#safety-rspecexpectchange]
2134
+ === Safety
2135
+
2136
+ Autocorrection is unsafe because `block` style evaluates the object
2137
+ twice (before and after evaluating `expect` block), whereas
2138
+ `method_call` style evaluates the object only once.
2139
+
2140
+ If you currently pass a block to `change` and expect the object to
2141
+ be evaluated before and after `expect` block, changing to
2142
+ `method_call` style may break your test.
2143
+
2133
2144
[#examples-rspecexpectchange]
2134
2145
=== Examples
2135
2146
Original file line number Diff line number Diff line change @@ -10,6 +10,15 @@ module RSpec
10
10
#
11
11
# This cop can be configured using the `EnforcedStyle` option.
12
12
#
13
+ # @safety
14
+ # Autocorrection is unsafe because `block` style evaluates the object
15
+ # twice (before and after evaluating `expect` block), whereas
16
+ # `method_call` style evaluates the object only once.
17
+ #
18
+ # If you currently pass a block to `change` and expect the object to
19
+ # be evaluated before and after `expect` block, changing to
20
+ # `method_call` style may break your test.
21
+ #
13
22
# @example `EnforcedStyle: method_call` (default)
14
23
# # bad
15
24
# expect { run }.to change { Foo.bar }
You can’t perform that action at this time.
0 commit comments