rubocop-rspec 2.1.0 → 2.2.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 +6 -0
- data/config/default.yml +1 -0
- data/lib/rubocop-rspec.rb +1 -0
- data/lib/rubocop/cop/rspec/any_instance.rb +6 -10
- data/lib/rubocop/cop/rspec/be_eql.rb +1 -0
- data/lib/rubocop/cop/rspec/before_after_all.rb +2 -0
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +2 -0
- data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +2 -0
- data/lib/rubocop/cop/rspec/describe_symbol.rb +1 -0
- data/lib/rubocop/cop/rspec/expect_change.rb +1 -0
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +1 -0
- data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +1 -0
- data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +1 -0
- data/lib/rubocop/cop/rspec/implicit_subject.rb +1 -0
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -0
- data/lib/rubocop/cop/rspec/message_chain.rb +4 -10
- data/lib/rubocop/cop/rspec/message_expectation.rb +1 -0
- data/lib/rubocop/cop/rspec/mixin/comments_help.rb +38 -0
- data/lib/rubocop/cop/rspec/not_to_not.rb +1 -0
- data/lib/rubocop/cop/rspec/rails/http_status.rb +1 -0
- data/lib/rubocop/cop/rspec/receive_counts.rb +2 -0
- data/lib/rubocop/cop/rspec/receive_never.rb +1 -0
- data/lib/rubocop/cop/rspec/return_from_stub.rb +1 -0
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +1 -0
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +1 -0
- data/lib/rubocop/cop/rspec/verified_doubles.rb +1 -0
- data/lib/rubocop/cop/rspec/void_expect.rb +1 -0
- data/lib/rubocop/rspec/corrector/move_node.rb +6 -9
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1531e973244c7aac66856335d340dee502696e988f9816bf74e7f5555d80d90
|
4
|
+
data.tar.gz: b634d15c53e126f497928eca6adfa6fae08b095ccb1a93f3d906826bca56efd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e91e8656f9f82f02fa041d5795d01eba023460aad4e3c06b55167b3f92fc0d22324250e1d116eb63c3b60e915240347f0a36cbe14c8b3752f7c6a63ea9949bd4
|
7
|
+
data.tar.gz: 8c470782145e23962f3653beb13b4543d461a3de9bbea201d5fb0c66fc8bfebb5695afad7bc545b37dba664362dee8edb0f579441f0bafcd963ab86f503b0415
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 2.2.0 (2021-02-02)
|
6
|
+
|
7
|
+
* Fix `HooksBeforeExamples`, `LeadingSubject`, `LetBeforeExamples` and `ScatteredLet` autocorrection to take into account inline comments and comments immediately before the moved node. ([@Darhazer][])
|
8
|
+
* Improve rubocop-rspec performance. ([@Darhazer][], [@bquorning][])
|
9
|
+
* Include `Enabled: true` to prevent a mismatched configuration parameter warning when `RSpec` cops are explicitly enabled in the user configuration. ([@pirj][])
|
10
|
+
|
5
11
|
## 2.1.0 (2020-12-17)
|
6
12
|
|
7
13
|
* Fix `RSpec/FilePath` false positive for relative file path runs with long namespaces. ([@ahukkanen][])
|
data/config/default.yml
CHANGED
data/lib/rubocop-rspec.rb
CHANGED
@@ -15,6 +15,7 @@ require_relative 'rubocop/rspec/language'
|
|
15
15
|
require_relative 'rubocop/cop/rspec/mixin/top_level_group'
|
16
16
|
require_relative 'rubocop/cop/rspec/mixin/variable'
|
17
17
|
require_relative 'rubocop/cop/rspec/mixin/final_end_location'
|
18
|
+
require_relative 'rubocop/cop/rspec/mixin/comments_help'
|
18
19
|
require_relative 'rubocop/cop/rspec/mixin/empty_line_separation'
|
19
20
|
|
20
21
|
require_relative 'rubocop/rspec/concept'
|
@@ -24,18 +24,14 @@ module RuboCop
|
|
24
24
|
# end
|
25
25
|
class AnyInstance < Base
|
26
26
|
MSG = 'Avoid stubbing using `%<method>s`.'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
RESTRICT_ON_SEND = %i[
|
28
|
+
any_instance
|
29
|
+
allow_any_instance_of
|
30
|
+
expect_any_instance_of
|
31
|
+
].freeze
|
31
32
|
|
32
33
|
def on_send(node)
|
33
|
-
|
34
|
-
add_offense(
|
35
|
-
node,
|
36
|
-
message: format(MSG, method: method)
|
37
|
-
)
|
38
|
-
end
|
34
|
+
add_offense(node, message: format(MSG, method: node.method_name))
|
39
35
|
end
|
40
36
|
end
|
41
37
|
end
|
@@ -29,6 +29,8 @@ module RuboCop
|
|
29
29
|
'`use_transactional_fixtures` is enabled, then records created ' \
|
30
30
|
'in `%<hook>s` are not automatically rolled back.'
|
31
31
|
|
32
|
+
RESTRICT_ON_SEND = %i[before after].freeze
|
33
|
+
|
32
34
|
def_node_matcher :before_or_after_all, <<-PATTERN
|
33
35
|
$(send _ {:before :after} (sym {:all :context}))
|
34
36
|
PATTERN
|
@@ -30,6 +30,8 @@ module RuboCop
|
|
30
30
|
'Capybara feature specs - instead, use the ' \
|
31
31
|
'`have_current_path` matcher on `page`'
|
32
32
|
|
33
|
+
RESTRICT_ON_SEND = %i[expect].freeze
|
34
|
+
|
33
35
|
def_node_matcher :expectation_set_on_current_path, <<-PATTERN
|
34
36
|
(send nil? :expect (send {(send nil? :page) nil?} :current_path))
|
35
37
|
PATTERN
|
@@ -19,6 +19,7 @@ module RuboCop
|
|
19
19
|
# @see https://github.com/rspec/rspec-core/issues/1610
|
20
20
|
class DescribeSymbol < Base
|
21
21
|
MSG = 'Avoid describing symbols.'
|
22
|
+
RESTRICT_ON_SEND = %i[describe].freeze
|
22
23
|
|
23
24
|
def_node_matcher :describe_symbol?, <<-PATTERN
|
24
25
|
(send #rspec? :describe $sym ...)
|
@@ -35,6 +35,7 @@ module RuboCop
|
|
35
35
|
|
36
36
|
MSG_BLOCK = 'Prefer `change(%<obj>s, :%<attr>s)`.'
|
37
37
|
MSG_CALL = 'Prefer `change { %<obj>s.%<attr>s }`.'
|
38
|
+
RESTRICT_ON_SEND = %i[change].freeze
|
38
39
|
|
39
40
|
def_node_matcher :expect_change_with_arguments, <<-PATTERN
|
40
41
|
(send nil? :change ({const send} nil? $_) (sym $_))
|
@@ -25,6 +25,7 @@ module RuboCop
|
|
25
25
|
MSG = "Pass '%<class_name>s' string instead of `%<class_name>s` " \
|
26
26
|
'constant.'
|
27
27
|
ALLOWED_CONSTANTS = %w[Hash OpenStruct].freeze
|
28
|
+
RESTRICT_ON_SEND = %i[factory].freeze
|
28
29
|
|
29
30
|
def_node_matcher :class_name, <<~PATTERN
|
30
31
|
(send _ :factory _ (hash <(pair (sym :class) $(const ...)) ...>))
|
@@ -31,6 +31,7 @@ module RuboCop
|
|
31
31
|
include ConfigurableEnforcedStyle
|
32
32
|
|
33
33
|
MSG = "Don't use implicit subject."
|
34
|
+
RESTRICT_ON_SEND = %i[is_expected should should_not].freeze
|
34
35
|
|
35
36
|
def_node_matcher :implicit_subject?, <<-PATTERN
|
36
37
|
(send nil? {:should :should_not :is_expected} ...)
|
@@ -24,6 +24,7 @@ module RuboCop
|
|
24
24
|
|
25
25
|
MSG = 'Prefer `%<replacement>s` over `%<original>s` when including ' \
|
26
26
|
'examples in a nested context.'
|
27
|
+
RESTRICT_ON_SEND = %i[it_behaves_like it_should_behave_like].freeze
|
27
28
|
|
28
29
|
def_node_matcher :example_inclusion_offense, '(send _ % ...)'
|
29
30
|
|
@@ -15,18 +15,12 @@ module RuboCop
|
|
15
15
|
#
|
16
16
|
class MessageChain < Base
|
17
17
|
MSG = 'Avoid stubbing using `%<method>s`.'
|
18
|
-
|
19
|
-
def_node_matcher :message_chain, <<-PATTERN
|
20
|
-
(send _ {:receive_message_chain :stub_chain} ...)
|
21
|
-
PATTERN
|
18
|
+
RESTRICT_ON_SEND = %i[receive_message_chain stub_chain].freeze
|
22
19
|
|
23
20
|
def on_send(node)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
message: format(MSG, method: node.method_name)
|
28
|
-
)
|
29
|
-
end
|
21
|
+
add_offense(
|
22
|
+
node.loc.selector, message: format(MSG, method: node.method_name)
|
23
|
+
)
|
30
24
|
end
|
31
25
|
end
|
32
26
|
end
|
@@ -30,6 +30,7 @@ module RuboCop
|
|
30
30
|
MSG = 'Prefer `%<style>s` for setting message expectations.'
|
31
31
|
|
32
32
|
SUPPORTED_STYLES = %w[allow expect].freeze
|
33
|
+
RESTRICT_ON_SEND = %i[to].freeze
|
33
34
|
|
34
35
|
def_node_matcher :message_expectation, <<-PATTERN
|
35
36
|
(send $(send nil? {:expect :allow} ...) :to #receive_message?)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Help methods for working with nodes containing comments.
|
7
|
+
module CommentsHelp
|
8
|
+
include FinalEndLocation
|
9
|
+
|
10
|
+
def source_range_with_comment(node)
|
11
|
+
begin_pos = begin_pos_with_comment(node).begin_pos
|
12
|
+
end_pos = end_line_position(node).end_pos
|
13
|
+
|
14
|
+
Parser::Source::Range.new(buffer, begin_pos, end_pos)
|
15
|
+
end
|
16
|
+
|
17
|
+
def begin_pos_with_comment(node)
|
18
|
+
first_comment = processed_source.ast_with_comments[node].first
|
19
|
+
|
20
|
+
start_line_position(first_comment || node)
|
21
|
+
end
|
22
|
+
|
23
|
+
def start_line_position(node)
|
24
|
+
buffer.line_range(node.loc.line)
|
25
|
+
end
|
26
|
+
|
27
|
+
def end_line_position(node)
|
28
|
+
end_line = buffer.line_for_position(final_end_location(node).end_pos)
|
29
|
+
buffer.line_range(end_line)
|
30
|
+
end
|
31
|
+
|
32
|
+
def buffer
|
33
|
+
processed_source.buffer
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -39,6 +39,7 @@ module RuboCop
|
|
39
39
|
|
40
40
|
MSG_AND_RETURN = 'Use `and_return` for static values.'
|
41
41
|
MSG_BLOCK = 'Use block for static values.'
|
42
|
+
RESTRICT_ON_SEND = %i[and_return].freeze
|
42
43
|
|
43
44
|
def_node_search :contains_stub?, '(send nil? :receive (...))'
|
44
45
|
def_node_matcher :stub_with_block?, '(block #contains_stub? ...)'
|
@@ -21,6 +21,7 @@ module RuboCop
|
|
21
21
|
|
22
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
|
|
25
26
|
def_node_matcher :message_chain, <<-PATTERN
|
26
27
|
(send _ {:receive_message_chain :stub_chain} $_)
|
@@ -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)
|
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.2.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-02-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -198,6 +198,7 @@ files:
|
|
198
198
|
- lib/rubocop/cop/rspec/message_expectation.rb
|
199
199
|
- lib/rubocop/cop/rspec/message_spies.rb
|
200
200
|
- lib/rubocop/cop/rspec/missing_example_group_argument.rb
|
201
|
+
- lib/rubocop/cop/rspec/mixin/comments_help.rb
|
201
202
|
- lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
|
202
203
|
- lib/rubocop/cop/rspec/mixin/final_end_location.rb
|
203
204
|
- lib/rubocop/cop/rspec/mixin/top_level_group.rb
|