rubocop-rspec 2.0.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -0
- data/README.md +3 -3
- data/config/default.yml +141 -125
- data/lib/rubocop-rspec.rb +1 -0
- data/lib/rubocop/cop/rspec/any_instance.rb +6 -10
- data/lib/rubocop/cop/rspec/around_block.rb +3 -1
- data/lib/rubocop/cop/rspec/be.rb +2 -1
- data/lib/rubocop/cop/rspec/be_eql.rb +2 -0
- data/lib/rubocop/cop/rspec/before_after_all.rb +6 -3
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +5 -0
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -0
- data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +4 -0
- data/lib/rubocop/cop/rspec/context_method.rb +1 -0
- data/lib/rubocop/cop/rspec/context_wording.rb +7 -1
- data/lib/rubocop/cop/rspec/describe_class.rb +4 -1
- data/lib/rubocop/cop/rspec/describe_method.rb +2 -1
- data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -0
- data/lib/rubocop/cop/rspec/described_class.rb +6 -1
- data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +2 -1
- data/lib/rubocop/cop/rspec/dialect.rb +1 -0
- data/lib/rubocop/cop/rspec/empty_hook.rb +1 -0
- data/lib/rubocop/cop/rspec/example_length.rb +26 -12
- data/lib/rubocop/cop/rspec/example_without_description.rb +1 -0
- data/lib/rubocop/cop/rspec/example_wording.rb +1 -0
- data/lib/rubocop/cop/rspec/expect_actual.rb +2 -0
- data/lib/rubocop/cop/rspec/expect_change.rb +6 -3
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -0
- data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +3 -0
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +4 -0
- data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +2 -0
- data/lib/rubocop/cop/rspec/file_path.rb +31 -20
- data/lib/rubocop/cop/rspec/focus.rb +33 -1
- data/lib/rubocop/cop/rspec/hook_argument.rb +2 -0
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +1 -0
- data/lib/rubocop/cop/rspec/identical_equality_assertion.rb +38 -0
- data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +4 -0
- data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -0
- data/lib/rubocop/cop/rspec/implicit_subject.rb +19 -1
- data/lib/rubocop/cop/rspec/instance_spy.rb +3 -1
- data/lib/rubocop/cop/rspec/instance_variable.rb +4 -0
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +3 -1
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -1
- data/lib/rubocop/cop/rspec/let_before_examples.rb +1 -0
- data/lib/rubocop/cop/rspec/let_setup.rb +3 -0
- data/lib/rubocop/cop/rspec/message_chain.rb +4 -10
- data/lib/rubocop/cop/rspec/message_expectation.rb +3 -0
- data/lib/rubocop/cop/rspec/message_spies.rb +4 -2
- data/lib/rubocop/cop/rspec/mixin/comments_help.rb +38 -0
- data/lib/rubocop/cop/rspec/mixin/variable.rb +1 -0
- data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -2
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +3 -0
- data/lib/rubocop/cop/rspec/named_subject.rb +3 -0
- data/lib/rubocop/cop/rspec/not_to_not.rb +2 -0
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +2 -0
- data/lib/rubocop/cop/rspec/pending.rb +4 -0
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +5 -0
- data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +44 -0
- data/lib/rubocop/cop/rspec/rails/http_status.rb +2 -0
- data/lib/rubocop/cop/rspec/receive_counts.rb +4 -0
- data/lib/rubocop/cop/rspec/receive_never.rb +2 -0
- data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +8 -1
- data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +4 -0
- data/lib/rubocop/cop/rspec/repeated_include_example.rb +3 -0
- data/lib/rubocop/cop/rspec/return_from_stub.rb +6 -0
- data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/shared_context.rb +6 -5
- data/lib/rubocop/cop/rspec/shared_examples.rb +1 -0
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +4 -1
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +1 -0
- data/lib/rubocop/cop/rspec/subject_stub.rb +15 -4
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +2 -0
- data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -0
- data/lib/rubocop/cop/rspec/void_expect.rb +3 -0
- data/lib/rubocop/cop/rspec/yield.rb +3 -0
- data/lib/rubocop/cop/rspec_cops.rb +2 -0
- data/lib/rubocop/rspec/config_formatter.rb +3 -1
- data/lib/rubocop/rspec/corrector/move_node.rb +6 -9
- data/lib/rubocop/rspec/example.rb +5 -0
- data/lib/rubocop/rspec/hook.rb +1 -0
- data/lib/rubocop/rspec/language.rb +10 -0
- data/lib/rubocop/rspec/node.rb +1 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +9 -6
@@ -19,13 +19,16 @@ module RuboCop
|
|
19
19
|
class SingleArgumentMessageChain < Base
|
20
20
|
extend AutoCorrector
|
21
21
|
|
22
|
-
MSG = 'Use `%<recommended>s` instead of calling '\
|
22
|
+
MSG = 'Use `%<recommended>s` instead of calling ' \
|
23
23
|
'`%<called>s` with a single argument.'
|
24
|
+
RESTRICT_ON_SEND = %i[receive_message_chain stub_chain].freeze
|
24
25
|
|
26
|
+
# @!method message_chain(node)
|
25
27
|
def_node_matcher :message_chain, <<-PATTERN
|
26
28
|
(send _ {:receive_message_chain :stub_chain} $_)
|
27
29
|
PATTERN
|
28
30
|
|
31
|
+
# @!method single_key_hash?(node)
|
29
32
|
def_node_matcher :single_key_hash?, '(hash pair)'
|
30
33
|
|
31
34
|
def on_send(node)
|
@@ -13,11 +13,21 @@ module RuboCop
|
|
13
13
|
#
|
14
14
|
# @example
|
15
15
|
# # bad
|
16
|
-
# describe
|
17
|
-
# subject(:
|
16
|
+
# describe Article do
|
17
|
+
# subject(:article) { Article.new }
|
18
18
|
#
|
19
|
-
#
|
20
|
-
# allow(
|
19
|
+
# it 'indicates that the author is unknown' do
|
20
|
+
# allow(article).to receive(:author).and_return(nil)
|
21
|
+
# expect(article.description).to include('by an unknown author')
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# # good
|
26
|
+
# describe Article do
|
27
|
+
# subject(:article) { Article.new(author: nil) }
|
28
|
+
#
|
29
|
+
# it 'indicates that the author is unknown' do
|
30
|
+
# expect(article.description).to include('by an unknown author')
|
21
31
|
# end
|
22
32
|
# end
|
23
33
|
#
|
@@ -71,6 +81,7 @@ module RuboCop
|
|
71
81
|
)
|
72
82
|
PATTERN
|
73
83
|
|
84
|
+
# @!method message_expectation_matcher?(node)
|
74
85
|
def_node_search :message_expectation_matcher?, <<-PATTERN
|
75
86
|
(send nil? {
|
76
87
|
:receive :receive_messages :receive_message_chain :have_received
|
@@ -32,7 +32,9 @@ module RuboCop
|
|
32
32
|
# expect { do_something }.not_to raise_error
|
33
33
|
class UnspecifiedException < Base
|
34
34
|
MSG = 'Specify the exception being captured'
|
35
|
+
RESTRICT_ON_SEND = %i[to].freeze
|
35
36
|
|
37
|
+
# @!method empty_raise_error_or_exception(node)
|
36
38
|
def_node_matcher :empty_raise_error_or_exception, <<-PATTERN
|
37
39
|
(send
|
38
40
|
(block
|
@@ -24,7 +24,9 @@ module RuboCop
|
|
24
24
|
# end
|
25
25
|
class VerifiedDoubles < Base
|
26
26
|
MSG = 'Prefer using verifying doubles over normal doubles.'
|
27
|
+
RESTRICT_ON_SEND = %i[double spy].freeze
|
27
28
|
|
29
|
+
# @!method unverified_double(node)
|
28
30
|
def_node_matcher :unverified_double, <<-PATTERN
|
29
31
|
{(send nil? {:double :spy} $...)}
|
30
32
|
PATTERN
|
@@ -14,11 +14,14 @@ module RuboCop
|
|
14
14
|
class VoidExpect < Base
|
15
15
|
MSG = 'Do not use `expect()` without `.to` or `.not_to`. ' \
|
16
16
|
'Chain the methods or remove it.'
|
17
|
+
RESTRICT_ON_SEND = %i[expect].freeze
|
17
18
|
|
19
|
+
# @!method expect?(node)
|
18
20
|
def_node_matcher :expect?, <<-PATTERN
|
19
21
|
(send nil? :expect ...)
|
20
22
|
PATTERN
|
21
23
|
|
24
|
+
# @!method expect_block?(node)
|
22
25
|
def_node_matcher :expect_block?, <<-PATTERN
|
23
26
|
(block #expect? (args) _body)
|
24
27
|
PATTERN
|
@@ -17,10 +17,13 @@ module RuboCop
|
|
17
17
|
|
18
18
|
MSG = 'Use `.and_yield`.'
|
19
19
|
|
20
|
+
# @!method method_on_stub?(node)
|
20
21
|
def_node_search :method_on_stub?, '(send nil? :receive ...)'
|
21
22
|
|
23
|
+
# @!method block_arg(node)
|
22
24
|
def_node_matcher :block_arg, '(args (blockarg $_))'
|
23
25
|
|
26
|
+
# @!method block_call?(node)
|
24
27
|
def_node_matcher :block_call?, '(send (lvar %) :call ...)'
|
25
28
|
|
26
29
|
def on_block(node)
|
@@ -8,6 +8,7 @@ require_relative 'rspec/factory_bot/attribute_defined_statically'
|
|
8
8
|
require_relative 'rspec/factory_bot/create_list'
|
9
9
|
require_relative 'rspec/factory_bot/factory_class_name'
|
10
10
|
|
11
|
+
require_relative 'rspec/rails/avoid_setup_hook'
|
11
12
|
begin
|
12
13
|
require_relative 'rspec/rails/http_status'
|
13
14
|
rescue LoadError
|
@@ -47,6 +48,7 @@ require_relative 'rspec/file_path'
|
|
47
48
|
require_relative 'rspec/focus'
|
48
49
|
require_relative 'rspec/hook_argument'
|
49
50
|
require_relative 'rspec/hooks_before_examples'
|
51
|
+
require_relative 'rspec/identical_equality_assertion'
|
50
52
|
require_relative 'rspec/implicit_block_expectation'
|
51
53
|
require_relative 'rspec/implicit_expect'
|
52
54
|
require_relative 'rspec/implicit_subject'
|
@@ -6,6 +6,7 @@ module RuboCop
|
|
6
6
|
# Helper methods to move a node
|
7
7
|
class MoveNode
|
8
8
|
include RuboCop::Cop::RangeHelp
|
9
|
+
include RuboCop::Cop::RSpec::CommentsHelp
|
9
10
|
include RuboCop::Cop::RSpec::FinalEndLocation
|
10
11
|
|
11
12
|
attr_reader :original, :corrector, :processed_source
|
@@ -17,20 +18,16 @@ module RuboCop
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def move_before(other)
|
20
|
-
position = other
|
21
|
-
indent = ' ' * other.loc.column
|
22
|
-
newline_indent = "\n#{indent}"
|
21
|
+
position = start_line_position(other)
|
23
22
|
|
24
|
-
corrector.insert_before(position, source(original)
|
23
|
+
corrector.insert_before(position, "#{source(original)}\n")
|
25
24
|
corrector.remove(node_range_with_surrounding_space(original))
|
26
25
|
end
|
27
26
|
|
28
27
|
def move_after(other)
|
29
|
-
position =
|
30
|
-
indent = ' ' * other.loc.column
|
31
|
-
newline_indent = "\n#{indent}"
|
28
|
+
position = end_line_position(other)
|
32
29
|
|
33
|
-
corrector.insert_after(position,
|
30
|
+
corrector.insert_after(position, "\n#{source(original)}")
|
34
31
|
corrector.remove(node_range_with_surrounding_space(original))
|
35
32
|
end
|
36
33
|
|
@@ -41,7 +38,7 @@ module RuboCop
|
|
41
38
|
end
|
42
39
|
|
43
40
|
def node_range(node)
|
44
|
-
|
41
|
+
source_range_with_comment(node)
|
45
42
|
end
|
46
43
|
|
47
44
|
def node_range_with_surrounding_space(node)
|
@@ -4,8 +4,13 @@ module RuboCop
|
|
4
4
|
module RSpec
|
5
5
|
# Wrapper for RSpec examples
|
6
6
|
class Example < Concept
|
7
|
+
# @!method extract_doc_string(node)
|
7
8
|
def_node_matcher :extract_doc_string, '(send _ _ $_ ...)'
|
9
|
+
|
10
|
+
# @!method extract_metadata(node)
|
8
11
|
def_node_matcher :extract_metadata, '(send _ _ _ $...)'
|
12
|
+
|
13
|
+
# @!method extract_implementation(node)
|
9
14
|
def_node_matcher :extract_implementation, '(block send args $_)'
|
10
15
|
|
11
16
|
def doc_string
|
data/lib/rubocop/rspec/hook.rb
CHANGED
@@ -19,23 +19,31 @@ module RuboCop
|
|
19
19
|
attr_accessor :config
|
20
20
|
end
|
21
21
|
|
22
|
+
# @!method rspec?(node)
|
22
23
|
def_node_matcher :rspec?, '{(const {nil? cbase} :RSpec) nil?}'
|
23
24
|
|
25
|
+
# @!method example_group?(node)
|
24
26
|
def_node_matcher :example_group?, block_pattern('#ExampleGroups.all')
|
25
27
|
|
28
|
+
# @!method shared_group?(node)
|
26
29
|
def_node_matcher :shared_group?, block_pattern('#SharedGroups.all')
|
27
30
|
|
31
|
+
# @!method spec_group?(node)
|
28
32
|
def_node_matcher :spec_group?,
|
29
33
|
block_pattern('{#SharedGroups.all #ExampleGroups.all}')
|
30
34
|
|
35
|
+
# @!method example_group_with_body?(node)
|
31
36
|
def_node_matcher :example_group_with_body?, <<-PATTERN
|
32
37
|
(block #{send_pattern('#ExampleGroups.all')} args !nil?)
|
33
38
|
PATTERN
|
34
39
|
|
40
|
+
# @!method example?(node)
|
35
41
|
def_node_matcher :example?, block_pattern('#Examples.all')
|
36
42
|
|
43
|
+
# @!method hook?(node)
|
37
44
|
def_node_matcher :hook?, block_pattern('#Hooks.all')
|
38
45
|
|
46
|
+
# @!method let?(node)
|
39
47
|
def_node_matcher :let?, <<-PATTERN
|
40
48
|
{
|
41
49
|
#{block_pattern('#Helpers.all')}
|
@@ -43,6 +51,7 @@ module RuboCop
|
|
43
51
|
}
|
44
52
|
PATTERN
|
45
53
|
|
54
|
+
# @!method include?(node)
|
46
55
|
def_node_matcher :include?, <<-PATTERN
|
47
56
|
{
|
48
57
|
#{send_pattern('#Includes.all')}
|
@@ -50,6 +59,7 @@ module RuboCop
|
|
50
59
|
}
|
51
60
|
PATTERN
|
52
61
|
|
62
|
+
# @!method subject?(node)
|
53
63
|
def_node_matcher :subject?, block_pattern('#Subjects.all')
|
54
64
|
|
55
65
|
module ExampleGroups # :nodoc:
|
data/lib/rubocop/rspec/node.rb
CHANGED
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.4.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:
|
13
|
+
date: 2021-06-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- lib/rubocop/cop/rspec/focus.rb
|
184
184
|
- lib/rubocop/cop/rspec/hook_argument.rb
|
185
185
|
- lib/rubocop/cop/rspec/hooks_before_examples.rb
|
186
|
+
- lib/rubocop/cop/rspec/identical_equality_assertion.rb
|
186
187
|
- lib/rubocop/cop/rspec/implicit_block_expectation.rb
|
187
188
|
- lib/rubocop/cop/rspec/implicit_expect.rb
|
188
189
|
- lib/rubocop/cop/rspec/implicit_subject.rb
|
@@ -198,6 +199,7 @@ files:
|
|
198
199
|
- lib/rubocop/cop/rspec/message_expectation.rb
|
199
200
|
- lib/rubocop/cop/rspec/message_spies.rb
|
200
201
|
- lib/rubocop/cop/rspec/missing_example_group_argument.rb
|
202
|
+
- lib/rubocop/cop/rspec/mixin/comments_help.rb
|
201
203
|
- lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
|
202
204
|
- lib/rubocop/cop/rspec/mixin/final_end_location.rb
|
203
205
|
- lib/rubocop/cop/rspec/mixin/top_level_group.rb
|
@@ -212,6 +214,7 @@ files:
|
|
212
214
|
- lib/rubocop/cop/rspec/overwriting_setup.rb
|
213
215
|
- lib/rubocop/cop/rspec/pending.rb
|
214
216
|
- lib/rubocop/cop/rspec/predicate_matcher.rb
|
217
|
+
- lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
|
215
218
|
- lib/rubocop/cop/rspec/rails/http_status.rb
|
216
219
|
- lib/rubocop/cop/rspec/receive_counts.rb
|
217
220
|
- lib/rubocop/cop/rspec/receive_never.rb
|
@@ -250,11 +253,11 @@ files:
|
|
250
253
|
- lib/rubocop/rspec/node.rb
|
251
254
|
- lib/rubocop/rspec/version.rb
|
252
255
|
- lib/rubocop/rspec/wording.rb
|
253
|
-
homepage: https://github.com/rubocop
|
256
|
+
homepage: https://github.com/rubocop/rubocop-rspec
|
254
257
|
licenses:
|
255
258
|
- MIT
|
256
259
|
metadata:
|
257
|
-
changelog_uri: https://github.com/rubocop
|
260
|
+
changelog_uri: https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md
|
258
261
|
documentation_uri: https://docs.rubocop.org/rubocop-rspec/
|
259
262
|
post_install_message:
|
260
263
|
rdoc_options: []
|
@@ -264,14 +267,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
264
267
|
requirements:
|
265
268
|
- - ">="
|
266
269
|
- !ruby/object:Gem::Version
|
267
|
-
version: 2.
|
270
|
+
version: 2.5.0
|
268
271
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
269
272
|
requirements:
|
270
273
|
- - ">="
|
271
274
|
- !ruby/object:Gem::Version
|
272
275
|
version: '0'
|
273
276
|
requirements: []
|
274
|
-
rubygems_version: 3.
|
277
|
+
rubygems_version: 3.2.16
|
275
278
|
signing_key:
|
276
279
|
specification_version: 4
|
277
280
|
summary: Code style checking for RSpec files
|