rubocop-rspec 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/config/default.yml +12 -0
- data/lib/rubocop/cop/rspec/be_eq.rb +45 -0
- data/lib/rubocop/cop/rspec/be_eql.rb +1 -1
- data/lib/rubocop/cop/rspec/be_nil.rb +40 -0
- data/lib/rubocop/cop/rspec_cops.rb +2 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d9511a08dde997c269b9bfe065a23b16296a607ce561a68bbe09ccd5eb37dee
|
4
|
+
data.tar.gz: 7966471067098d603c1098e544ad9c573e63037398126fbb9838aefbec992e25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8020a1e38b6c8bf50ebccd9524d9fd513193ec2bdb9829edb1832d456abbdf57bc8386a51f58b6b19ea335de5991c6dec182a428f9579dfc91d7871990f83c54
|
7
|
+
data.tar.gz: 91aaec82daf89de819e93f4cadea65928b0b2178465db8997c0f928feaf4d5a11a3ecd1e927ab401e50aed1081dcdde41499101b6f5b166ae380bfbf4c1bfd89
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 2.9.0 (2022-02-28)
|
6
|
+
|
7
|
+
* Add new `RSpec/BeNil` cop. ([@bquorning][])
|
8
|
+
* Add new `RSpec/BeEq` cop. ([@bquorning][])
|
9
|
+
|
5
10
|
## 2.8.0 (2022-01-24)
|
6
11
|
|
7
12
|
* Fix `RSpec/FactoryBot/SyntaxMethods` and `RSpec/Capybara/FeatureMethods` to inspect shared groups. ([@pirj][])
|
data/config/default.yml
CHANGED
@@ -142,12 +142,24 @@ RSpec/Be:
|
|
142
142
|
StyleGuide: https://rspec.rubystyle.guide/#be-matcher
|
143
143
|
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Be
|
144
144
|
|
145
|
+
RSpec/BeEq:
|
146
|
+
Description: Check for expectations where `be(...)` can replace `eq(...)`.
|
147
|
+
Enabled: pending
|
148
|
+
VersionAdded: 2.9.0
|
149
|
+
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEq
|
150
|
+
|
145
151
|
RSpec/BeEql:
|
146
152
|
Description: Check for expectations where `be(...)` can replace `eql(...)`.
|
147
153
|
Enabled: true
|
148
154
|
VersionAdded: '1.7'
|
149
155
|
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEql
|
150
156
|
|
157
|
+
RSpec/BeNil:
|
158
|
+
Description: Check that `be_nil` is used instead of `be(nil)`.
|
159
|
+
Enabled: pending
|
160
|
+
VersionAdded: 2.9.0
|
161
|
+
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeNil
|
162
|
+
|
151
163
|
RSpec/BeforeAfterAll:
|
152
164
|
Description: Check that before/after(:all) isn't being used.
|
153
165
|
Enabled: true
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Check for expectations where `be(...)` can replace `eq(...)`.
|
7
|
+
#
|
8
|
+
# The `be` matcher compares by identity while the `eq` matcher compares
|
9
|
+
# using `==`. Booleans and nil can be compared by identity and therefore
|
10
|
+
# the `be` matcher is preferable as it is a more strict test.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
#
|
14
|
+
# # bad
|
15
|
+
# expect(foo).to eq(true)
|
16
|
+
# expect(foo).to eq(false)
|
17
|
+
# expect(foo).to eq(nil)
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# expect(foo).to be(true)
|
21
|
+
# expect(foo).to be(false)
|
22
|
+
# expect(foo).to be(nil)
|
23
|
+
#
|
24
|
+
class BeEq < Base
|
25
|
+
extend AutoCorrector
|
26
|
+
|
27
|
+
MSG = 'Prefer `be` over `eq`.'
|
28
|
+
RESTRICT_ON_SEND = %i[eq].freeze
|
29
|
+
|
30
|
+
# @!method eq_type_with_identity?(node)
|
31
|
+
def_node_matcher :eq_type_with_identity?, <<-PATTERN
|
32
|
+
(send nil? :eq {true false nil})
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
def on_send(node)
|
36
|
+
return unless eq_type_with_identity?(node)
|
37
|
+
|
38
|
+
add_offense(node.loc.selector) do |corrector|
|
39
|
+
corrector.replace(node.loc.selector, 'be')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
|
44
44
|
# @!method eql_type_with_identity(node)
|
45
45
|
def_node_matcher :eql_type_with_identity, <<-PATTERN
|
46
|
-
(send _ :to $(send nil? :eql {true false int float sym
|
46
|
+
(send _ :to $(send nil? :eql {true false int float sym nil}))
|
47
47
|
PATTERN
|
48
48
|
|
49
49
|
def on_send(node)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Check that `be_nil` is used instead of `be(nil)`.
|
7
|
+
#
|
8
|
+
# RSpec has a built-in `be_nil` matcher specifically for expecting `nil`.
|
9
|
+
# For consistent specs, we recommend using that instead of `be(nil)`.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# expect(foo).to be(nil)
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# expect(foo).to be_nil
|
18
|
+
#
|
19
|
+
class BeNil < Base
|
20
|
+
extend AutoCorrector
|
21
|
+
|
22
|
+
MSG = 'Prefer `be_nil` over `be(nil)`.'
|
23
|
+
RESTRICT_ON_SEND = %i[be].freeze
|
24
|
+
|
25
|
+
# @!method nil_value_expectation?(node)
|
26
|
+
def_node_matcher :nil_value_expectation?, <<-PATTERN
|
27
|
+
(send nil? :be nil)
|
28
|
+
PATTERN
|
29
|
+
|
30
|
+
def on_send(node)
|
31
|
+
return unless nil_value_expectation?(node)
|
32
|
+
|
33
|
+
add_offense(node) do |corrector|
|
34
|
+
corrector.replace(node.loc.expression, 'be_nil')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -21,7 +21,9 @@ require_relative 'rspec/align_right_let_brace'
|
|
21
21
|
require_relative 'rspec/any_instance'
|
22
22
|
require_relative 'rspec/around_block'
|
23
23
|
require_relative 'rspec/be'
|
24
|
+
require_relative 'rspec/be_eq'
|
24
25
|
require_relative 'rspec/be_eql'
|
26
|
+
require_relative 'rspec/be_nil'
|
25
27
|
require_relative 'rspec/before_after_all'
|
26
28
|
require_relative 'rspec/context_method'
|
27
29
|
require_relative 'rspec/context_wording'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Backus
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-02-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -135,7 +135,9 @@ files:
|
|
135
135
|
- lib/rubocop/cop/rspec/around_block.rb
|
136
136
|
- lib/rubocop/cop/rspec/base.rb
|
137
137
|
- lib/rubocop/cop/rspec/be.rb
|
138
|
+
- lib/rubocop/cop/rspec/be_eq.rb
|
138
139
|
- lib/rubocop/cop/rspec/be_eql.rb
|
140
|
+
- lib/rubocop/cop/rspec/be_nil.rb
|
139
141
|
- lib/rubocop/cop/rspec/before_after_all.rb
|
140
142
|
- lib/rubocop/cop/rspec/capybara/current_path_expectation.rb
|
141
143
|
- lib/rubocop/cop/rspec/capybara/feature_methods.rb
|