rubocop-rspec 1.42.0 → 1.44.1
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 +44 -2
- data/config/default.yml +41 -3
- data/lib/rubocop-rspec.rb +2 -1
- 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 +1 -1
- data/lib/rubocop/cop/rspec/around_block.rb +2 -2
- data/lib/rubocop/cop/rspec/base.rb +76 -0
- data/lib/rubocop/cop/rspec/be.rb +1 -1
- data/lib/rubocop/cop/rspec/be_eql.rb +1 -1
- data/lib/rubocop/cop/rspec/before_after_all.rb +1 -1
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +1 -1
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +6 -3
- data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +1 -1
- data/lib/rubocop/cop/rspec/context_method.rb +2 -2
- data/lib/rubocop/cop/rspec/context_wording.rb +3 -3
- data/lib/rubocop/cop/rspec/cop.rb +2 -66
- data/lib/rubocop/cop/rspec/describe_class.rb +40 -30
- data/lib/rubocop/cop/rspec/describe_method.rb +14 -6
- data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -2
- data/lib/rubocop/cop/rspec/described_class.rb +2 -2
- data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +1 -1
- data/lib/rubocop/cop/rspec/dialect.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_example_group.rb +124 -6
- data/lib/rubocop/cop/rspec/empty_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_example.rb +4 -8
- data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +4 -8
- data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +7 -10
- data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +4 -8
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +5 -8
- data/lib/rubocop/cop/rspec/example_length.rb +1 -1
- data/lib/rubocop/cop/rspec/example_without_description.rb +1 -1
- data/lib/rubocop/cop/rspec/example_wording.rb +4 -4
- data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_change.rb +1 -1
- 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 +3 -3
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +10 -6
- data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +1 -1
- data/lib/rubocop/cop/rspec/file_path.rb +25 -17
- data/lib/rubocop/cop/rspec/focus.rb +7 -11
- data/lib/rubocop/cop/rspec/hook_argument.rb +5 -6
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +1 -1
- data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +2 -3
- data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -1
- data/lib/rubocop/cop/rspec/implicit_subject.rb +8 -6
- 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 +1 -1
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -1
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +1 -1
- data/lib/rubocop/cop/rspec/leading_subject.rb +24 -17
- data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +1 -1
- data/lib/rubocop/cop/rspec/let_before_examples.rb +1 -1
- data/lib/rubocop/cop/rspec/let_setup.rb +6 -3
- data/lib/rubocop/cop/rspec/message_chain.rb +1 -1
- data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
- data/lib/rubocop/cop/rspec/message_spies.rb +1 -1
- data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_describes.rb +11 -8
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +7 -11
- data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +148 -0
- data/lib/rubocop/cop/rspec/multiple_subjects.rb +1 -1
- data/lib/rubocop/cop/rspec/named_subject.rb +1 -1
- data/lib/rubocop/cop/rspec/nested_groups.rb +4 -4
- data/lib/rubocop/cop/rspec/not_to_not.rb +1 -1
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/pending.rb +1 -1
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +7 -14
- data/lib/rubocop/cop/rspec/rails/http_status.rb +1 -1
- data/lib/rubocop/cop/rspec/receive_counts.rb +1 -1
- data/lib/rubocop/cop/rspec/receive_never.rb +2 -2
- data/lib/rubocop/cop/rspec/repeated_description.rb +1 -1
- data/lib/rubocop/cop/rspec/repeated_example.rb +2 -2
- data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +1 -1
- data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +1 -1
- data/lib/rubocop/cop/rspec/repeated_include_example.rb +103 -0
- data/lib/rubocop/cop/rspec/return_from_stub.rb +1 -1
- 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 +1 -1
- data/lib/rubocop/cop/rspec/shared_examples.rb +1 -1
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +1 -1
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +172 -0
- data/lib/rubocop/cop/rspec/subject_stub.rb +6 -6
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +1 -1
- data/lib/rubocop/cop/rspec/variable_definition.rb +6 -6
- data/lib/rubocop/cop/rspec/variable_name.rb +28 -9
- data/lib/rubocop/cop/rspec/verified_doubles.rb +1 -1
- data/lib/rubocop/cop/rspec/void_expect.rb +1 -1
- data/lib/rubocop/cop/rspec/yield.rb +1 -1
- data/lib/rubocop/cop/rspec_cops.rb +3 -0
- data/lib/rubocop/rspec/corrector/move_node.rb +7 -5
- data/lib/rubocop/rspec/description_extractor.rb +1 -1
- data/lib/rubocop/rspec/{blank_line_separation.rb → empty_line_separation.rb} +13 -2
- data/lib/rubocop/rspec/example_group.rb +2 -2
- data/lib/rubocop/rspec/hook.rb +1 -5
- data/lib/rubocop/rspec/language.rb +12 -5
- data/lib/rubocop/rspec/language/node_pattern.rb +6 -1
- data/lib/rubocop/rspec/top_level_describe.rb +2 -2
- data/lib/rubocop/rspec/top_level_group.rb +26 -13
- data/lib/rubocop/rspec/variable.rb +1 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +38 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd834ceb18475775328b46ac9c17d5b0d44b718c0a78a72ec82bd14730624de8
|
4
|
+
data.tar.gz: f68ba33f60563a6f8ab4264ee2bc42ee4fd5a34e838c2961ef0286e88f1986bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee6383660785ebd59d6fe885f107550c59e1881f838f1c51c21bbdd3b6bbd78ef0c0f8fc0935c06df0237da5927a223de0e3adf9a1abdb1262bffa9877e5e213
|
7
|
+
data.tar.gz: 02c425dc74c4b898a718330ead4679dfcdc4405a6c5fde2bfe78c4c4796a1e96617c185612abfe1c812039ccd8bccce1da2fe3ef37b53c835f9eff6d22d4d62b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,41 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 1.44.1 (2020-10-20)
|
6
|
+
|
7
|
+
* Relax `rubocop-ast` version constraint. ([@PhilCoggins][])
|
8
|
+
|
9
|
+
## 1.44.0 (2020-10-20)
|
10
|
+
|
11
|
+
* Move our documentation from rubocop-rspec.readthedocs.io to docs.rubocop.org/rubocop-rspec. ([@bquorning][])
|
12
|
+
* Add `RSpec/RepeatedIncludeExample` cop. ([@biinari][])
|
13
|
+
* Add `RSpec/StubbedMock` cop. ([@bquorning][], [@pirj][])
|
14
|
+
* Add `IgnoredMetadata` configuration option to `RSpec/DescribeClass`. ([@Rafix02][])
|
15
|
+
* Fix false positives in `RSpec/EmptyExampleGroup`. ([@pirj][])
|
16
|
+
* Fix a false positive for `RSpec/EmptyExampleGroup` when example is defined in an `if` branch. ([@koic][])
|
17
|
+
|
18
|
+
## 1.43.2 (2020-08-25)
|
19
|
+
|
20
|
+
* Fix `RSpec/FilePath` when checking a file with a shared example. ([@pirj][])
|
21
|
+
* Fix subject nesting detection in `RSpec/LeadingSubject`. ([@pirj][])
|
22
|
+
|
23
|
+
## 1.43.1 (2020-08-17)
|
24
|
+
|
25
|
+
* Fix `RSpec/FilePath` when checking a file defining e.g. an empty class. ([@bquorning][])
|
26
|
+
|
27
|
+
## 1.43.0 (2020-08-17)
|
28
|
+
|
29
|
+
* Add a new base cop class `::RuboCop::Cop::RSpec::Base`. The old base class `::RuboCop::Cop::RSpec::Cop` is deprecated, and will be removed in the next major release. ([@bquorning][])
|
30
|
+
* Add support for subject detection after includes and example groups in `RSpec/LeadingSubject`. ([@pirj][])
|
31
|
+
* Ignore trailing punctuation in context description prefix. ([@elliterate][])
|
32
|
+
* Relax `RSpec/VariableDefinition` cop so interpolated and multiline strings are accepted even when configured to enforce the `symbol` style. ([@bquorning][])
|
33
|
+
* Fix `RSpec/EmptyExampleGroup` to flag example groups with examples in invalid scopes. ([@mlarraz][])
|
34
|
+
* Fix `RSpec/EmptyExampleGroup` to ignore examples groups with examples defined inside iterators. ([@pirj][])
|
35
|
+
* Improve `RSpec/NestedGroups`, `RSpec/FilePath`, `RSpec/DescribeMethod`, `RSpec/MultipleDescribes`, `RSpec/DescribeClass`'s top-level example group detection. ([@pirj][])
|
36
|
+
* Add detection of `let!` with a block-pass or a string literal to `RSpec/LetSetup`. ([@pirj][])
|
37
|
+
* Add `IgnoredPatterns` configuration option to `RSpec/VariableName`. ([@jtannas][])
|
38
|
+
* Add `RSpec/MultipleMemoizedHelpers` cop. ([@mockdeep][])
|
39
|
+
|
5
40
|
## 1.42.0 (2020-07-09)
|
6
41
|
|
7
42
|
* Update RuboCop dependency to 0.87.0 because of changes to internal APIs. ([@bquorning][], [@Darhazer][])
|
@@ -484,8 +519,8 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
|
484
519
|
[@rspeicher]: https://github.com/rspeicher
|
485
520
|
[@jonatas]: https://github.com/jonatas
|
486
521
|
[@pocke]: https://github.com/pocke
|
487
|
-
[@bmorrall]: https
|
488
|
-
[@zverok]: https
|
522
|
+
[@bmorrall]: https://github.com/bmorrall
|
523
|
+
[@zverok]: https://github.com/zverok
|
489
524
|
[@timrogers]: https://github.com/timrogers
|
490
525
|
[@yevhene]: https://github.com/yevhene
|
491
526
|
[@walf443]: https://github.com/walf443
|
@@ -529,3 +564,10 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
|
529
564
|
[@rolfschmidt]: https://github.com/rolfschmidt
|
530
565
|
[@andrykonchin]: https://github.com/andrykonchin
|
531
566
|
[@harrylewis]: https://github.com/harrylewis
|
567
|
+
[@elliterate]: https://github.com/elliterate
|
568
|
+
[@jtannas]: https://github.com/jtannas
|
569
|
+
[@mockdeep]: https://github.com/mockdeep
|
570
|
+
[@biinari]: https://github.com/biinari
|
571
|
+
[@koic]: https://github.com/koic
|
572
|
+
[@Rafix02]: https://github.com/Rafix02
|
573
|
+
[@PhilCoggins]: https://github.com/PhilCoggins
|
data/config/default.yml
CHANGED
@@ -74,9 +74,25 @@ RSpec/ContextWording:
|
|
74
74
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ContextWording
|
75
75
|
|
76
76
|
RSpec/DescribeClass:
|
77
|
-
Description: Check that the first argument to the top
|
78
|
-
Enabled: true
|
77
|
+
Description: Check that the first argument to the top-level describe is a constant.
|
78
|
+
Enabled: true
|
79
|
+
IgnoredMetadata:
|
80
|
+
type:
|
81
|
+
- channel
|
82
|
+
- controller
|
83
|
+
- helper
|
84
|
+
- job
|
85
|
+
- mailer
|
86
|
+
- model
|
87
|
+
- request
|
88
|
+
- routing
|
89
|
+
- view
|
90
|
+
- feature
|
91
|
+
- system
|
92
|
+
- mailbox
|
93
|
+
- aruba
|
79
94
|
VersionAdded: '1.0'
|
95
|
+
VersionChanged: '1.44'
|
80
96
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeClass
|
81
97
|
|
82
98
|
RSpec/DescribeMethod:
|
@@ -381,7 +397,7 @@ RSpec/MissingExampleGroupArgument:
|
|
381
397
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MissingExampleGroupArgument
|
382
398
|
|
383
399
|
RSpec/MultipleDescribes:
|
384
|
-
Description: Checks for multiple top
|
400
|
+
Description: Checks for multiple top-level example groups.
|
385
401
|
Enabled: true
|
386
402
|
VersionAdded: '1.0'
|
387
403
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleDescribes
|
@@ -394,6 +410,14 @@ RSpec/MultipleExpectations:
|
|
394
410
|
VersionChanged: '1.21'
|
395
411
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleExpectations
|
396
412
|
|
413
|
+
RSpec/MultipleMemoizedHelpers:
|
414
|
+
Description: Checks if example groups contain too many `let` and `subject` calls.
|
415
|
+
Enabled: true
|
416
|
+
AllowSubject: true
|
417
|
+
Max: 5
|
418
|
+
VersionAdded: '1.43'
|
419
|
+
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers
|
420
|
+
|
397
421
|
RSpec/MultipleSubjects:
|
398
422
|
Description: Checks if an example group defines `subject` multiple times.
|
399
423
|
Enabled: true
|
@@ -486,6 +510,12 @@ RSpec/RepeatedExampleGroupDescription:
|
|
486
510
|
VersionAdded: '1.38'
|
487
511
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedExampleGroupDescription
|
488
512
|
|
513
|
+
RSpec/RepeatedIncludeExample:
|
514
|
+
Description: Check for repeated include of shared examples.
|
515
|
+
Enabled: true
|
516
|
+
VersionAdded: '1.44'
|
517
|
+
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedIncludeExample
|
518
|
+
|
489
519
|
RSpec/ReturnFromStub:
|
490
520
|
Description: Checks for consistent style of stub's return setting.
|
491
521
|
Enabled: true
|
@@ -529,6 +559,12 @@ RSpec/SingleArgumentMessageChain:
|
|
529
559
|
VersionChanged: '1.10'
|
530
560
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SingleArgumentMessageChain
|
531
561
|
|
562
|
+
RSpec/StubbedMock:
|
563
|
+
Description: Checks that message expectations do not have a configured response.
|
564
|
+
Enabled: pending
|
565
|
+
VersionAdded: '1.44'
|
566
|
+
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/StubbedMock
|
567
|
+
|
532
568
|
RSpec/SubjectStub:
|
533
569
|
Description: Checks for stubbed test subjects.
|
534
570
|
Enabled: true
|
@@ -558,7 +594,9 @@ RSpec/VariableName:
|
|
558
594
|
SupportedStyles:
|
559
595
|
- snake_case
|
560
596
|
- camelCase
|
597
|
+
IgnoredPatterns: []
|
561
598
|
VersionAdded: '1.40'
|
599
|
+
VersionChanged: '1.43'
|
562
600
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VariableName
|
563
601
|
|
564
602
|
RSpec/VerifiedDoubles:
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -19,11 +19,12 @@ require_relative 'rubocop/rspec/example_group'
|
|
19
19
|
require_relative 'rubocop/rspec/example'
|
20
20
|
require_relative 'rubocop/rspec/hook'
|
21
21
|
require_relative 'rubocop/rspec/variable'
|
22
|
+
require_relative 'rubocop/cop/rspec/base'
|
22
23
|
require_relative 'rubocop/cop/rspec/cop'
|
23
24
|
require_relative 'rubocop/rspec/align_let_brace'
|
24
25
|
require_relative 'rubocop/rspec/factory_bot'
|
25
26
|
require_relative 'rubocop/rspec/final_end_location'
|
26
|
-
require_relative 'rubocop/rspec/
|
27
|
+
require_relative 'rubocop/rspec/empty_line_separation'
|
27
28
|
require_relative 'rubocop/rspec/corrector/move_node'
|
28
29
|
|
29
30
|
RuboCop::RSpec::Inject.defaults!
|
@@ -25,13 +25,13 @@ module RuboCop
|
|
25
25
|
# some_method
|
26
26
|
# test.run
|
27
27
|
# end
|
28
|
-
class AroundBlock <
|
28
|
+
class AroundBlock < Base
|
29
29
|
MSG_NO_ARG = 'Test object should be passed to around block.'
|
30
30
|
MSG_UNUSED_ARG = 'You should call `%<arg>s.call` '\
|
31
31
|
'or `%<arg>s.run`.'
|
32
32
|
|
33
33
|
def_node_matcher :hook, <<-PATTERN
|
34
|
-
(block
|
34
|
+
(block (send nil? :around sym ?) (args $...) ...)
|
35
35
|
PATTERN
|
36
36
|
|
37
37
|
def_node_search :find_arg_usage, <<-PATTERN
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# @abstract parent class to RSpec cops
|
7
|
+
#
|
8
|
+
# The criteria for whether rubocop-rspec analyzes a certain ruby file
|
9
|
+
# is configured via `AllCops/RSpec`. For example, if you want to
|
10
|
+
# customize your project to scan all files within a `test/` directory
|
11
|
+
# then you could add this to your configuration:
|
12
|
+
#
|
13
|
+
# @example configuring analyzed paths
|
14
|
+
# # .rubocop.yml
|
15
|
+
# # AllCops:
|
16
|
+
# # RSpec:
|
17
|
+
# # Patterns:
|
18
|
+
# # - '_test.rb$'
|
19
|
+
# # - '(?:^|/)test/'
|
20
|
+
class Base < ::RuboCop::Cop::Base
|
21
|
+
include RuboCop::RSpec::Language
|
22
|
+
include RuboCop::RSpec::Language::NodePattern
|
23
|
+
|
24
|
+
DEFAULT_CONFIGURATION =
|
25
|
+
RuboCop::RSpec::CONFIG.fetch('AllCops').fetch('RSpec')
|
26
|
+
|
27
|
+
DEFAULT_PATTERN_RE = Regexp.union(
|
28
|
+
DEFAULT_CONFIGURATION.fetch('Patterns')
|
29
|
+
.map(&Regexp.public_method(:new))
|
30
|
+
)
|
31
|
+
|
32
|
+
exclude_from_registry
|
33
|
+
|
34
|
+
# Invoke the original inherited hook so our cops are recognized
|
35
|
+
def self.inherited(subclass) # rubocop:disable Lint/MissingSuper
|
36
|
+
RuboCop::Cop::Base.inherited(subclass)
|
37
|
+
end
|
38
|
+
|
39
|
+
def relevant_file?(file)
|
40
|
+
relevant_rubocop_rspec_file?(file) && super
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def relevant_rubocop_rspec_file?(file)
|
46
|
+
rspec_pattern.match?(file)
|
47
|
+
end
|
48
|
+
|
49
|
+
def rspec_pattern
|
50
|
+
if rspec_pattern_config?
|
51
|
+
Regexp.union(rspec_pattern_config.map(&Regexp.public_method(:new)))
|
52
|
+
else
|
53
|
+
DEFAULT_PATTERN_RE
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def all_cops_config
|
58
|
+
config
|
59
|
+
.for_all_cops
|
60
|
+
end
|
61
|
+
|
62
|
+
def rspec_pattern_config?
|
63
|
+
return unless all_cops_config.key?('RSpec')
|
64
|
+
|
65
|
+
all_cops_config.fetch('RSpec').key?('Patterns')
|
66
|
+
end
|
67
|
+
|
68
|
+
def rspec_pattern_config
|
69
|
+
all_cops_config
|
70
|
+
.fetch('RSpec', DEFAULT_CONFIGURATION)
|
71
|
+
.fetch('Patterns')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/rubocop/cop/rspec/be.rb
CHANGED
@@ -23,7 +23,7 @@ module RuboCop
|
|
23
23
|
# before(:each) { Widget.create }
|
24
24
|
# after(:each) { Widget.delete_all }
|
25
25
|
# end
|
26
|
-
class BeforeAfterAll <
|
26
|
+
class BeforeAfterAll < Base
|
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 '\
|
@@ -23,7 +23,7 @@ module RuboCop
|
|
23
23
|
# expect(page).to have_current_path("/callback")
|
24
24
|
# expect(page).to have_current_path(/widgets/)
|
25
25
|
#
|
26
|
-
class CurrentPathExpectation <
|
26
|
+
class CurrentPathExpectation < Base
|
27
27
|
extend AutoCorrector
|
28
28
|
|
29
29
|
MSG = 'Do not set an RSpec expectation on `current_path` in ' \
|
@@ -40,7 +40,7 @@ module RuboCop
|
|
40
40
|
# # ...
|
41
41
|
# end
|
42
42
|
# end
|
43
|
-
class FeatureMethods <
|
43
|
+
class FeatureMethods < Base
|
44
44
|
extend AutoCorrector
|
45
45
|
|
46
46
|
MSG = 'Use `%<replacement>s` instead of `%<method>s`.'
|
@@ -55,15 +55,18 @@ module RuboCop
|
|
55
55
|
feature: :describe
|
56
56
|
}.freeze
|
57
57
|
|
58
|
+
def_node_matcher :capybara_speak,
|
59
|
+
SelectorSet.new(MAP.keys).node_pattern_union
|
60
|
+
|
58
61
|
def_node_matcher :spec?, <<-PATTERN
|
59
62
|
(block
|
60
|
-
(send #
|
63
|
+
(send #rspec? {:describe :feature} ...)
|
61
64
|
...)
|
62
65
|
PATTERN
|
63
66
|
|
64
67
|
def_node_matcher :feature_method, <<-PATTERN
|
65
68
|
(block
|
66
|
-
$(send #
|
69
|
+
$(send #rspec? $#capybara_speak ...)
|
67
70
|
...)
|
68
71
|
PATTERN
|
69
72
|
|
@@ -26,7 +26,7 @@ module RuboCop
|
|
26
26
|
# expect(page).to have_css('.foo', visible: :all)
|
27
27
|
# expect(page).to have_link('my link', visible: :hidden)
|
28
28
|
#
|
29
|
-
class VisibilityMatcher <
|
29
|
+
class VisibilityMatcher < Base
|
30
30
|
MSG_FALSE = 'Use `:all` or `:hidden` instead of `false`.'
|
31
31
|
MSG_TRUE = 'Use `:visible` instead of `true`.'
|
32
32
|
CAPYBARA_MATCHER_METHODS = %i[
|
@@ -23,13 +23,13 @@ module RuboCop
|
|
23
23
|
# describe '.foo_bar' do
|
24
24
|
# # ...
|
25
25
|
# end
|
26
|
-
class ContextMethod <
|
26
|
+
class ContextMethod < Base
|
27
27
|
extend AutoCorrector
|
28
28
|
|
29
29
|
MSG = 'Use `describe` for testing methods.'
|
30
30
|
|
31
31
|
def_node_matcher :context_method, <<-PATTERN
|
32
|
-
(block (send #
|
32
|
+
(block (send #rspec? :context $(str #method_name?) ...) ...)
|
33
33
|
PATTERN
|
34
34
|
|
35
35
|
def on_block(node)
|
@@ -34,11 +34,11 @@ module RuboCop
|
|
34
34
|
# context 'when the display name is not present' do
|
35
35
|
# # ...
|
36
36
|
# end
|
37
|
-
class ContextWording <
|
37
|
+
class ContextWording < Base
|
38
38
|
MSG = 'Start context description with %<prefixes>s.'
|
39
39
|
|
40
40
|
def_node_matcher :context_wording, <<-PATTERN
|
41
|
-
(block (send #
|
41
|
+
(block (send #rspec? { :context :shared_context } $(str #bad_prefix?) ...) ...)
|
42
42
|
PATTERN
|
43
43
|
|
44
44
|
def on_block(node)
|
@@ -51,7 +51,7 @@ module RuboCop
|
|
51
51
|
private
|
52
52
|
|
53
53
|
def bad_prefix?(description)
|
54
|
-
!prefixes.include?(description.split.first)
|
54
|
+
!prefixes.include?(description.split(/\b/).first)
|
55
55
|
end
|
56
56
|
|
57
57
|
def joined_prefixes
|
@@ -3,72 +3,8 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module RSpec
|
6
|
-
# @
|
7
|
-
|
8
|
-
# The criteria for whether rubocop-rspec analyzes a certain ruby file
|
9
|
-
# is configured via `AllCops/RSpec`. For example, if you want to
|
10
|
-
# customize your project to scan all files within a `test/` directory
|
11
|
-
# then you could add this to your configuration:
|
12
|
-
#
|
13
|
-
# @example configuring analyzed paths
|
14
|
-
# # .rubocop.yml
|
15
|
-
# # AllCops:
|
16
|
-
# # RSpec:
|
17
|
-
# # Patterns:
|
18
|
-
# # - '_test.rb$'
|
19
|
-
# # - '(?:^|/)test/'
|
20
|
-
class Cop < ::RuboCop::Cop::Base
|
21
|
-
include RuboCop::RSpec::Language
|
22
|
-
include RuboCop::RSpec::Language::NodePattern
|
23
|
-
|
24
|
-
DEFAULT_CONFIGURATION =
|
25
|
-
RuboCop::RSpec::CONFIG.fetch('AllCops').fetch('RSpec')
|
26
|
-
|
27
|
-
DEFAULT_PATTERN_RE = Regexp.union(
|
28
|
-
DEFAULT_CONFIGURATION.fetch('Patterns')
|
29
|
-
.map(&Regexp.public_method(:new))
|
30
|
-
)
|
31
|
-
|
32
|
-
# Invoke the original inherited hook so our cops are recognized
|
33
|
-
def self.inherited(subclass)
|
34
|
-
RuboCop::Cop::Cop.inherited(subclass)
|
35
|
-
end
|
36
|
-
|
37
|
-
def relevant_file?(file)
|
38
|
-
relevant_rubocop_rspec_file?(file) && super
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def relevant_rubocop_rspec_file?(file)
|
44
|
-
rspec_pattern =~ file
|
45
|
-
end
|
46
|
-
|
47
|
-
def rspec_pattern
|
48
|
-
if rspec_pattern_config?
|
49
|
-
Regexp.union(rspec_pattern_config.map(&Regexp.public_method(:new)))
|
50
|
-
else
|
51
|
-
DEFAULT_PATTERN_RE
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def all_cops_config
|
56
|
-
config
|
57
|
-
.for_all_cops
|
58
|
-
end
|
59
|
-
|
60
|
-
def rspec_pattern_config?
|
61
|
-
return unless all_cops_config.key?('RSpec')
|
62
|
-
|
63
|
-
all_cops_config.fetch('RSpec').key?('Patterns')
|
64
|
-
end
|
65
|
-
|
66
|
-
def rspec_pattern_config
|
67
|
-
all_cops_config
|
68
|
-
.fetch('RSpec', DEFAULT_CONFIGURATION)
|
69
|
-
.fetch('Patterns')
|
70
|
-
end
|
71
|
-
end
|
6
|
+
# @deprecated Use ::RuboCop::Cop::RSpec::Base instead
|
7
|
+
Cop = Base
|
72
8
|
end
|
73
9
|
end
|
74
10
|
end
|