rubocop-rspec 1.32.0 → 1.33.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 +11 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/config/default.yml +6 -0
- data/lib/rubocop-rspec.rb +3 -0
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +1 -1
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +1 -1
- data/lib/rubocop/cop/rspec/any_instance.rb +3 -1
- data/lib/rubocop/cop/rspec/around_block.rb +4 -2
- data/lib/rubocop/cop/rspec/be.rb +4 -2
- data/lib/rubocop/cop/rspec/be_eql.rb +3 -1
- data/lib/rubocop/cop/rspec/before_after_all.rb +1 -1
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +5 -3
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -3
- data/lib/rubocop/cop/rspec/context_wording.rb +2 -2
- data/lib/rubocop/cop/rspec/describe_class.rb +4 -4
- data/lib/rubocop/cop/rspec/describe_method.rb +2 -2
- data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -2
- data/lib/rubocop/cop/rspec/described_class.rb +3 -3
- data/lib/rubocop/cop/rspec/dialect.rb +76 -0
- data/lib/rubocop/cop/rspec/empty_example_group.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +1 -1
- data/lib/rubocop/cop/rspec/example_length.rb +1 -1
- data/lib/rubocop/cop/rspec/example_without_description.rb +2 -2
- data/lib/rubocop/cop/rspec/example_wording.rb +2 -2
- data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_change.rb +2 -2
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +21 -40
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +2 -2
- data/lib/rubocop/cop/rspec/file_path.rb +2 -2
- data/lib/rubocop/cop/rspec/focus.rb +3 -3
- data/lib/rubocop/cop/rspec/hook_argument.rb +4 -6
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +2 -5
- data/lib/rubocop/cop/rspec/implicit_expect.rb +2 -2
- data/lib/rubocop/cop/rspec/implicit_subject.rb +1 -1
- data/lib/rubocop/cop/rspec/instance_spy.rb +1 -1
- data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
- data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +4 -2
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -1
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -1
- data/lib/rubocop/cop/rspec/leading_subject.rb +1 -2
- data/lib/rubocop/cop/rspec/let_before_examples.rb +2 -5
- data/lib/rubocop/cop/rspec/let_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/message_chain.rb +3 -1
- data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
- data/lib/rubocop/cop/rspec/message_spies.rb +3 -4
- data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_subjects.rb +6 -2
- data/lib/rubocop/cop/rspec/named_subject.rb +1 -1
- data/lib/rubocop/cop/rspec/nested_groups.rb +3 -4
- data/lib/rubocop/cop/rspec/not_to_not.rb +3 -1
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/pending.rb +3 -3
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +17 -14
- data/lib/rubocop/cop/rspec/rails/http_status.rb +2 -2
- data/lib/rubocop/cop/rspec/receive_counts.rb +5 -6
- data/lib/rubocop/cop/rspec/receive_never.rb +4 -7
- data/lib/rubocop/cop/rspec/repeated_description.rb +3 -1
- data/lib/rubocop/cop/rspec/repeated_example.rb +3 -1
- data/lib/rubocop/cop/rspec/return_from_stub.rb +2 -2
- data/lib/rubocop/cop/rspec/scattered_let.rb +1 -1
- data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/shared_context.rb +2 -2
- data/lib/rubocop/cop/rspec/shared_examples.rb +7 -7
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +3 -1
- data/lib/rubocop/cop/rspec/subject_stub.rb +1 -1
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +5 -3
- data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -2
- data/lib/rubocop/cop/rspec/void_expect.rb +1 -1
- data/lib/rubocop/cop/rspec/yield.rb +2 -4
- data/lib/rubocop/cop/rspec_cops.rb +3 -0
- data/lib/rubocop/rspec.rb +2 -0
- data/lib/rubocop/rspec/blank_line_separation.rb +3 -1
- data/lib/rubocop/rspec/config_formatter.rb +3 -1
- data/lib/rubocop/rspec/description_extractor.rb +3 -1
- data/lib/rubocop/rspec/factory_bot.rb +58 -0
- data/lib/rubocop/rspec/final_end_location.rb +2 -0
- data/lib/rubocop/rspec/inject.rb +2 -0
- data/lib/rubocop/rspec/language.rb +9 -2
- data/lib/rubocop/rspec/top_level_describe.rb +2 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/rubocop-rspec.gemspec +3 -1
- data/spec/project/changelog_spec.rb +2 -0
- data/spec/project/default_config_spec.rb +2 -0
- data/spec/project/project_requires_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +22 -37
- data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +21 -36
- data/spec/rubocop/cop/rspec/any_instance_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/around_block_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/be_eql_spec.rb +25 -4
- data/spec/rubocop/cop/rspec/be_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/before_after_all_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/context_wording_spec.rb +32 -0
- data/spec/rubocop/cop/rspec/describe_class_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/describe_method_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/described_class_spec.rb +4 -1
- data/spec/rubocop/cop/rspec/dialect_spec.rb +78 -0
- data/spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb +40 -21
- data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +77 -69
- data/spec/rubocop/cop/rspec/empty_line_after_hook_spec.rb +24 -19
- data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +16 -19
- data/spec/rubocop/cop/rspec/example_length_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/example_without_description_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +45 -24
- data/spec/rubocop/cop/rspec/expect_change_spec.rb +22 -14
- data/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +36 -0
- data/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/file_path_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/focus_spec.rb +2 -2
- data/spec/rubocop/cop/rspec/hook_argument_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/hooks_before_examples_spec.rb +47 -32
- data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +20 -19
- data/spec/rubocop/cop/rspec/implicit_subject_spec.rb +56 -68
- data/spec/rubocop/cop/rspec/instance_spy_spec.rb +16 -15
- data/spec/rubocop/cop/rspec/instance_variable_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +10 -12
- data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/leading_subject_spec.rb +31 -47
- data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +27 -26
- data/spec/rubocop/cop/rspec/message_chain_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/missing_example_group_argument_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +24 -37
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +22 -32
- data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/pending_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/receive_counts_spec.rb +47 -8
- data/spec/rubocop/cop/rspec/receive_never_spec.rb +16 -4
- data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +95 -72
- data/spec/rubocop/cop/rspec/scattered_let_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/shared_context_spec.rb +29 -34
- data/spec/rubocop/cop/rspec/shared_examples_spec.rb +16 -34
- data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +44 -48
- data/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/void_expect_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/yield_spec.rb +22 -21
- data/spec/rubocop/rspec/config_formatter_spec.rb +2 -0
- data/spec/rubocop/rspec/description_extractor_spec.rb +2 -0
- data/spec/rubocop/rspec/language/selector_set_spec.rb +2 -0
- data/spec/rubocop/rspec/util/one_spec.rb +2 -0
- data/spec/rubocop/rspec/wording_spec.rb +2 -0
- data/spec/shared/autocorrect_behavior.rb +2 -0
- data/spec/shared/detects_style_behavior.rb +2 -0
- data/spec/shared/smoke_test_examples.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/expect_offense.rb +3 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53e671fa54f485f07186b567e9e44f7522db1e9508f5f723549c1f50f467ef68
|
4
|
+
data.tar.gz: 5f842a528fb62843a686e9674d4b94f5a44008afbc602c9babfb91ddf90ef4df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e03a650246098cb4498448db4e91846bb25643ea3673ec54db68678dbe80acefecbc69f20ca484addbea5f8a97a7dd84e3d21205b14da21cc74de45d8048501
|
7
|
+
data.tar.gz: 1d3cfdc4b32495be01056e6435bebaf1c1575bb37bda80973c31095ec4ce2f3556ce90ad9360e81102522869fa57c1f0eb6d005d670820b75df00c70e689131e
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 1.33.0 (2019-05-13)
|
6
|
+
|
7
|
+
* Let `RSpec/DescribedClass` pass `Struct` instantiation closures. ([@schmijos][])
|
8
|
+
* Fixed `RSpec/ContextWording` missing `context`s with metadata. ([@pirj][])
|
9
|
+
* Fix `FactoryBot/AttributeDefinedStatically` not working with an explicit receiver. ([@composerinteralia][])
|
10
|
+
* Add `RSpec/Dialect` enforces custom RSpec dialects. ([@gsamokovarov][])
|
11
|
+
* Fix redundant blank lines in `RSpec/MultipleSubjects`'s autocorrect. ([@pirj][])
|
12
|
+
* Drop support for ruby `2.2`. ([@bquorning][])
|
13
|
+
|
5
14
|
## 1.32.0 (2019-01-27)
|
6
15
|
|
7
16
|
* Add `RSpec/Yield` cop, suggesting using the `and_yield` method when stubbing a method, accepting a block. ([@Darhazer][])
|
@@ -407,3 +416,5 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
|
407
416
|
[@RST-J]: https://github.com/RST-J
|
408
417
|
[@ypresto]: https://github.com/ypresto
|
409
418
|
[@mkenyon]: https://github.com/mkenyon
|
419
|
+
[@gsamokovarov]: https://github.com/gsamokovarov
|
420
|
+
[@schmijos]: https://github.com/schmijos
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/config/default.yml
CHANGED
@@ -83,6 +83,12 @@ RSpec/DescribedClass:
|
|
83
83
|
- explicit
|
84
84
|
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClass
|
85
85
|
|
86
|
+
RSpec/Dialect:
|
87
|
+
Description: This cop enforces custom RSpec dialects.
|
88
|
+
Enabled: false
|
89
|
+
PreferredMethods: {}
|
90
|
+
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Dialect
|
91
|
+
|
86
92
|
RSpec/EmptyExampleGroup:
|
87
93
|
Description: Checks if an example group does not include any tests.
|
88
94
|
Enabled: true
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
require 'yaml'
|
3
5
|
|
@@ -18,6 +20,7 @@ require_relative 'rubocop/rspec/example'
|
|
18
20
|
require_relative 'rubocop/rspec/hook'
|
19
21
|
require_relative 'rubocop/cop/rspec/cop'
|
20
22
|
require_relative 'rubocop/rspec/align_let_brace'
|
23
|
+
require_relative 'rubocop/rspec/factory_bot'
|
21
24
|
require_relative 'rubocop/rspec/final_end_location'
|
22
25
|
require_relative 'rubocop/rspec/blank_line_separation'
|
23
26
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RuboCop
|
2
4
|
module Cop
|
3
5
|
module RSpec
|
@@ -21,7 +23,7 @@ module RuboCop
|
|
21
23
|
# end
|
22
24
|
# end
|
23
25
|
class AnyInstance < Cop
|
24
|
-
MSG = 'Avoid stubbing using `%<method>s`.'
|
26
|
+
MSG = 'Avoid stubbing using `%<method>s`.'
|
25
27
|
|
26
28
|
def_node_matcher :disallowed_stub, <<-PATTERN
|
27
29
|
(send _ ${:any_instance :allow_any_instance_of :expect_any_instance_of} ...)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RuboCop
|
2
4
|
module Cop
|
3
5
|
module RSpec
|
@@ -24,9 +26,9 @@ module RuboCop
|
|
24
26
|
# test.run
|
25
27
|
# end
|
26
28
|
class AroundBlock < Cop
|
27
|
-
MSG_NO_ARG = 'Test object should be passed to around block.'
|
29
|
+
MSG_NO_ARG = 'Test object should be passed to around block.'
|
28
30
|
MSG_UNUSED_ARG = 'You should call `%<arg>s.call` '\
|
29
|
-
'or `%<arg>s.run`.'
|
31
|
+
'or `%<arg>s.run`.'
|
30
32
|
|
31
33
|
def_node_matcher :hook, <<-PATTERN
|
32
34
|
(block {(send nil? :around) (send nil? :around sym)} (args $...) ...)
|
data/lib/rubocop/cop/rspec/be.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RuboCop
|
2
4
|
module Cop
|
3
5
|
module RSpec
|
@@ -18,10 +20,10 @@ module RuboCop
|
|
18
20
|
# expect(foo).to be(true)
|
19
21
|
#
|
20
22
|
class Be < Cop
|
21
|
-
MSG = 'Don\'t use `be` without an argument.'
|
23
|
+
MSG = 'Don\'t use `be` without an argument.'
|
22
24
|
|
23
25
|
def_node_matcher :be_without_args, <<-PATTERN
|
24
|
-
(send _ {
|
26
|
+
(send _ #{Runners::ALL.node_pattern_union} $(send nil? :be))
|
25
27
|
PATTERN
|
26
28
|
|
27
29
|
def on_send(node)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RuboCop
|
2
4
|
module Cop
|
3
5
|
module RSpec
|
@@ -34,7 +36,7 @@ module RuboCop
|
|
34
36
|
# coerce objects for comparison.
|
35
37
|
#
|
36
38
|
class BeEql < Cop
|
37
|
-
MSG = 'Prefer `be` over `eql`.'
|
39
|
+
MSG = 'Prefer `be` over `eql`.'
|
38
40
|
|
39
41
|
def_node_matcher :eql_type_with_identity, <<-PATTERN
|
40
42
|
(send _ :to $(send nil? :eql {true false int float sym nil_type?}))
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
MSG = 'Beware of using `%<hook>s` as it may cause state to leak '\
|
28
28
|
'between tests. If you are using `rspec-rails`, and '\
|
29
29
|
'`use_transactional_fixtures` is enabled, then records created '\
|
30
|
-
'in `%<hook>s` are not automatically rolled back.'
|
30
|
+
'in `%<hook>s` are not automatically rolled back.'
|
31
31
|
|
32
32
|
def_node_matcher :before_or_after_all, <<-PATTERN
|
33
33
|
$(send _ {:before :after} (sym {:all :context}))
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RuboCop
|
2
4
|
module Cop
|
3
5
|
module RSpec
|
@@ -24,7 +26,7 @@ module RuboCop
|
|
24
26
|
class CurrentPathExpectation < Cop
|
25
27
|
MSG = 'Do not set an RSpec expectation on `current_path` in ' \
|
26
28
|
'Capybara feature specs - instead, use the ' \
|
27
|
-
'`have_current_path` matcher on `page`'
|
29
|
+
'`have_current_path` matcher on `page`'
|
28
30
|
|
29
31
|
def_node_matcher :expectation_set_on_current_path, <<-PATTERN
|
30
32
|
(send nil? :expect (send {(send nil? :page) nil?} :current_path))
|
@@ -33,13 +35,13 @@ module RuboCop
|
|
33
35
|
# Supported matchers: eq(...) / match(/regexp/) / match('regexp')
|
34
36
|
def_node_matcher :as_is_matcher, <<-PATTERN
|
35
37
|
(send
|
36
|
-
#expectation_set_on_current_path
|
38
|
+
#expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
|
37
39
|
${(send nil? :eq ...) (send nil? :match (regexp ...))})
|
38
40
|
PATTERN
|
39
41
|
|
40
42
|
def_node_matcher :regexp_str_matcher, <<-PATTERN
|
41
43
|
(send
|
42
|
-
#expectation_set_on_current_path
|
44
|
+
#expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
|
43
45
|
$(send nil? :match (str $_)))
|
44
46
|
PATTERN
|
45
47
|
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
# end
|
42
42
|
# end
|
43
43
|
class FeatureMethods < Cop
|
44
|
-
MSG = 'Use `%<replacement>s` instead of `%<method>s`.'
|
44
|
+
MSG = 'Use `%<replacement>s` instead of `%<method>s`.'
|
45
45
|
|
46
46
|
# https://git.io/v7Kwr
|
47
47
|
MAP = {
|
@@ -55,13 +55,13 @@ module RuboCop
|
|
55
55
|
|
56
56
|
def_node_matcher :spec?, <<-PATTERN
|
57
57
|
(block
|
58
|
-
(send {
|
58
|
+
(send #{RSPEC} {:describe :feature} ...)
|
59
59
|
...)
|
60
60
|
PATTERN
|
61
61
|
|
62
62
|
def_node_matcher :feature_method, <<-PATTERN
|
63
63
|
(block
|
64
|
-
$(send {
|
64
|
+
$(send #{RSPEC} ${#{MAP.keys.map(&:inspect).join(' ')}} ...)
|
65
65
|
...)
|
66
66
|
PATTERN
|
67
67
|
|
@@ -27,10 +27,10 @@ module RuboCop
|
|
27
27
|
# # ...
|
28
28
|
# end
|
29
29
|
class ContextWording < Cop
|
30
|
-
MSG = 'Start context description with %<prefixes>s.'
|
30
|
+
MSG = 'Start context description with %<prefixes>s.'
|
31
31
|
|
32
32
|
def_node_matcher :context_wording, <<-PATTERN
|
33
|
-
(block (send
|
33
|
+
(block (send #{RSPEC} { :context :shared_context } $(str #bad_prefix?) ...) ...)
|
34
34
|
PATTERN
|
35
35
|
|
36
36
|
def on_block(node)
|
@@ -20,17 +20,17 @@ module RuboCop
|
|
20
20
|
include RuboCop::RSpec::TopLevelDescribe
|
21
21
|
|
22
22
|
MSG = 'The first argument to describe should be '\
|
23
|
-
'the class or module being tested.'
|
23
|
+
'the class or module being tested.'
|
24
24
|
|
25
25
|
def_node_matcher :valid_describe?, <<-PATTERN
|
26
26
|
{
|
27
|
-
(send {
|
28
|
-
(send {
|
27
|
+
(send #{RSPEC} :describe const ...)
|
28
|
+
(send #{RSPEC} :describe)
|
29
29
|
}
|
30
30
|
PATTERN
|
31
31
|
|
32
32
|
def_node_matcher :describe_with_metadata, <<-PATTERN
|
33
|
-
(send {
|
33
|
+
(send #{RSPEC} :describe
|
34
34
|
!const
|
35
35
|
...
|
36
36
|
(hash $...))
|
@@ -21,10 +21,10 @@ module RuboCop
|
|
21
21
|
include RuboCop::RSpec::Util
|
22
22
|
|
23
23
|
MSG = 'The second argument to describe should be the method '\
|
24
|
-
"being tested. '#instance' or '.class'."
|
24
|
+
"being tested. '#instance' or '.class'."
|
25
25
|
|
26
26
|
def on_top_level_describe(_node, (_, second_arg))
|
27
|
-
return unless second_arg
|
27
|
+
return unless second_arg&.str_type?
|
28
28
|
return if second_arg.str_content.start_with?('#', '.')
|
29
29
|
|
30
30
|
add_offense(second_arg, location: :expression)
|
@@ -18,10 +18,10 @@ module RuboCop
|
|
18
18
|
#
|
19
19
|
# @see https://github.com/rspec/rspec-core/issues/1610
|
20
20
|
class DescribeSymbol < Cop
|
21
|
-
MSG = 'Avoid describing symbols.'
|
21
|
+
MSG = 'Avoid describing symbols.'
|
22
22
|
|
23
23
|
def_node_matcher :describe_symbol?, <<-PATTERN
|
24
|
-
(send {
|
24
|
+
(send #{RSPEC} :describe $sym ...)
|
25
25
|
PATTERN
|
26
26
|
|
27
27
|
def on_send(node)
|
@@ -36,11 +36,11 @@ module RuboCop
|
|
36
36
|
include RuboCop::RSpec::TopLevelDescribe
|
37
37
|
include ConfigurableEnforcedStyle
|
38
38
|
|
39
|
-
DESCRIBED_CLASS = 'described_class'
|
40
|
-
MSG = 'Use `%<replacement>s` instead of `%<src>s`.'
|
39
|
+
DESCRIBED_CLASS = 'described_class'
|
40
|
+
MSG = 'Use `%<replacement>s` instead of `%<src>s`.'
|
41
41
|
|
42
42
|
def_node_matcher :common_instance_exec_closure?, <<-PATTERN
|
43
|
-
(block (send (const nil? {:Class :Module}) :new ...) ...)
|
43
|
+
(block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
|
44
44
|
PATTERN
|
45
45
|
|
46
46
|
def_node_matcher :rspec_block?,
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# This cop enforces custom RSpec dialects.
|
7
|
+
#
|
8
|
+
# A dialect can be based on the following RSpec methods:
|
9
|
+
#
|
10
|
+
# - describe, context, feature, example_group
|
11
|
+
# - xdescribe, xcontext, xfeature
|
12
|
+
# - fdescribe, fcontext, ffeature
|
13
|
+
# - shared_examples, shared_examples_for, shared_context
|
14
|
+
# - it, specify, example, scenario, its
|
15
|
+
# - fit, fspecify, fexample, fscenario, focus
|
16
|
+
# - xit, xspecify, xexample, xscenario, skip
|
17
|
+
# - pending
|
18
|
+
# - prepend_before, before, append_before,
|
19
|
+
# - around
|
20
|
+
# - prepend_after, after, append_after
|
21
|
+
# - let, let!
|
22
|
+
# - subject, subject!
|
23
|
+
# - expect, is_expected, expect_any_instance_of
|
24
|
+
#
|
25
|
+
# By default all of the RSpec methods and aliases are allowed. By setting
|
26
|
+
# a config like:
|
27
|
+
#
|
28
|
+
# RSpec/Dialect:
|
29
|
+
# PreferredMethods:
|
30
|
+
# context: describe
|
31
|
+
#
|
32
|
+
# You can expect the following behavior:
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# # bad
|
36
|
+
# context 'display name presence' do
|
37
|
+
# # ...
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# # good
|
41
|
+
# describe 'display name presence' do
|
42
|
+
# # ...
|
43
|
+
# end
|
44
|
+
class Dialect < Cop
|
45
|
+
include MethodPreference
|
46
|
+
|
47
|
+
MSG = 'Prefer `%<prefer>s` over `%<current>s`.'
|
48
|
+
|
49
|
+
def_node_matcher :rspec_method?, ALL.send_pattern
|
50
|
+
|
51
|
+
def on_send(node)
|
52
|
+
return unless rspec_method?(node)
|
53
|
+
return unless preferred_methods[node.method_name]
|
54
|
+
|
55
|
+
add_offense(node)
|
56
|
+
end
|
57
|
+
|
58
|
+
def autocorrect(node)
|
59
|
+
lambda do |corrector|
|
60
|
+
current = node.loc.selector
|
61
|
+
preferred = preferred_method(current.source)
|
62
|
+
|
63
|
+
corrector.replace(current, preferred)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def message(node)
|
70
|
+
format(MSG, prefer: preferred_method(node.method_name),
|
71
|
+
current: node.method_name)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -26,7 +26,7 @@ module RuboCop
|
|
26
26
|
class EmptyLineAfterExampleGroup < Cop
|
27
27
|
include RuboCop::RSpec::BlankLineSeparation
|
28
28
|
|
29
|
-
MSG = 'Add an empty line after `%<example_group>s`.'
|
29
|
+
MSG = 'Add an empty line after `%<example_group>s`.'
|
30
30
|
|
31
31
|
def on_block(node)
|
32
32
|
return unless example_group?(node)
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
class EmptyLineAfterFinalLet < Cop
|
20
20
|
include RuboCop::RSpec::BlankLineSeparation
|
21
21
|
|
22
|
-
MSG = 'Add an empty line after the last `let` block.'
|
22
|
+
MSG = 'Add an empty line after the last `let` block.'
|
23
23
|
|
24
24
|
def on_block(node)
|
25
25
|
return unless example_group_with_body?(node)
|
@@ -17,7 +17,7 @@ module RuboCop
|
|
17
17
|
class EmptyLineAfterSubject < Cop
|
18
18
|
include RuboCop::RSpec::BlankLineSeparation
|
19
19
|
|
20
|
-
MSG = 'Add empty line after `subject`.'
|
20
|
+
MSG = 'Add empty line after `subject`.'
|
21
21
|
|
22
22
|
def on_block(node)
|
23
23
|
return unless subject?(node) && !in_spec_block?(node)
|