rubocop-rspec 1.40.0 → 1.43.2
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 +37 -0
- data/CODE_OF_CONDUCT.md +17 -0
- data/config/default.yml +12 -2
- data/lib/rubocop-rspec.rb +3 -1
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +12 -19
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +12 -19
- data/lib/rubocop/cop/rspec/any_instance.rb +1 -1
- data/lib/rubocop/cop/rspec/around_block.rb +1 -1
- data/lib/rubocop/cop/rspec/base.rb +74 -0
- data/lib/rubocop/cop/rspec/be.rb +2 -2
- data/lib/rubocop/cop/rspec/be_eql.rb +6 -6
- data/lib/rubocop/cop/rspec/before_after_all.rb +1 -1
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +19 -17
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +14 -12
- data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +1 -1
- data/lib/rubocop/cop/rspec/context_method.rb +7 -9
- 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 +20 -27
- 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 +12 -9
- data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +1 -1
- data/lib/rubocop/cop/rspec/dialect.rb +5 -12
- data/lib/rubocop/cop/rspec/empty_example_group.rb +91 -7
- data/lib/rubocop/cop/rspec/empty_hook.rb +6 -10
- data/lib/rubocop/cop/rspec/empty_line_after_example.rb +5 -7
- data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +5 -9
- data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +8 -8
- data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +5 -9
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +6 -6
- 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 +10 -11
- data/lib/rubocop/cop/rspec/expect_actual.rb +8 -11
- data/lib/rubocop/cop/rspec/expect_change.rb +10 -35
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +3 -3
- data/lib/rubocop/cop/rspec/expect_output.rb +2 -2
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +24 -21
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +20 -22
- data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +7 -8
- 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 +16 -23
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +13 -14
- data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +1 -1
- data/lib/rubocop/cop/rspec/implicit_expect.rb +7 -15
- data/lib/rubocop/cop/rspec/implicit_subject.rb +16 -11
- data/lib/rubocop/cop/rspec/instance_spy.rb +18 -12
- data/lib/rubocop/cop/rspec/instance_variable.rb +4 -8
- data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +3 -6
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +5 -6
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +1 -1
- data/lib/rubocop/cop/rspec/leading_subject.rb +27 -20
- data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +2 -5
- data/lib/rubocop/cop/rspec/let_before_examples.rb +13 -11
- data/lib/rubocop/cop/rspec/let_setup.rb +21 -6
- data/lib/rubocop/cop/rspec/message_chain.rb +7 -6
- data/lib/rubocop/cop/rspec/message_expectation.rb +2 -2
- data/lib/rubocop/cop/rspec/message_spies.rb +2 -3
- 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 +18 -19
- data/lib/rubocop/cop/rspec/named_subject.rb +2 -2
- data/lib/rubocop/cop/rspec/nested_groups.rb +12 -13
- data/lib/rubocop/cop/rspec/not_to_not.rb +5 -6
- 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 +32 -69
- data/lib/rubocop/cop/rspec/rails/http_status.rb +5 -9
- data/lib/rubocop/cop/rspec/receive_counts.rb +15 -17
- data/lib/rubocop/cop/rspec/receive_never.rb +12 -12
- 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/return_from_stub.rb +12 -22
- data/lib/rubocop/cop/rspec/scattered_let.rb +8 -11
- data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/shared_context.rb +8 -21
- data/lib/rubocop/cop/rspec/shared_examples.rb +6 -9
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +15 -18
- data/lib/rubocop/cop/rspec/subject_stub.rb +5 -11
- 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 +14 -11
- data/lib/rubocop/cop/rspec_cops.rb +1 -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 -10
- data/lib/rubocop/rspec/example_group.rb +21 -49
- data/lib/rubocop/rspec/factory_bot.rb +7 -1
- data/lib/rubocop/rspec/language.rb +6 -4
- data/lib/rubocop/rspec/language/node_pattern.rb +10 -1
- data/lib/rubocop/rspec/top_level_describe.rb +2 -2
- data/lib/rubocop/rspec/top_level_group.rb +57 -0
- data/lib/rubocop/rspec/variable.rb +1 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +29 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d294600ca379bc470a03a4f321754ddafd18ccc67f405dfe4b7be415d7486354
|
4
|
+
data.tar.gz: 465ba74f6309c23bbe0473a11fff879240f84ae22edce0ce71735e0597d64b93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bc9d6c638aaa87f89af987ffeed7d169becaa8d95a3798442285a5dfdb0fff0150bd092f5fbef047b14366c451f9682a3d1fd8f35c1e2a4f48902d586eff3be
|
7
|
+
data.tar.gz: db4bf7903df2e82900c01d4318dcccdfd10be7ce251d2b472d1fb321f79523505f077d7683325060ad626b82dc52c3ee462ff437a1f7dff668492264f99d45db
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,38 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 1.43.2 (2020-08-25)
|
6
|
+
|
7
|
+
* Fix `RSpec/FilePath` when checking a file with a shared example. ([@pirj][])
|
8
|
+
* Fix subject nesting detection in `RSpec/LeadingSubject`. ([@pirj][])
|
9
|
+
|
10
|
+
## 1.43.1 (2020-08-17)
|
11
|
+
|
12
|
+
* Fix `RSpec/FilePath` when checking a file defining e.g. an empty class. ([@bquorning][])
|
13
|
+
|
14
|
+
## 1.43.0 (2020-08-17)
|
15
|
+
|
16
|
+
* 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][])
|
17
|
+
* Add support for subject detection after includes and example groups in `RSpec/LeadingSubject`. ([@pirj][])
|
18
|
+
* Ignore trailing punctuation in context description prefix. ([@elliterate][])
|
19
|
+
* Relax `RSpec/VariableDefinition` cop so interpolated and multiline strings are accepted even when configured to enforce the `symbol` style. ([@bquorning][])
|
20
|
+
* Fix `RSpec/EmptyExampleGroup` to flag example groups with examples in invalid scopes. ([@mlarraz][])
|
21
|
+
* Fix `RSpec/EmptyExampleGroup` to ignore examples groups with examples defined inside iterators. ([@pirj][])
|
22
|
+
* Improve `RSpec/NestedGroups`, `RSpec/FilePath`, `RSpec/DescribeMethod`, `RSpec/MultipleDescribes`, `RSpec/DescribeClass`'s top-level example group detection. ([@pirj][])
|
23
|
+
* Add detection of `let!` with a block-pass or a string literal to `RSpec/LetSetup`. ([@pirj][])
|
24
|
+
* Add `IgnoredPatterns` configuration option to `RSpec/VariableName`. ([@jtannas][])
|
25
|
+
* Add `RSpec/MultipleMemoizedHelpers` cop. ([@mockdeep][])
|
26
|
+
|
27
|
+
## 1.42.0 (2020-07-09)
|
28
|
+
|
29
|
+
* Update RuboCop dependency to 0.87.0 because of changes to internal APIs. ([@bquorning][], [@Darhazer][])
|
30
|
+
|
31
|
+
## 1.41.0 (2020-07-03)
|
32
|
+
|
33
|
+
* Extend the list of Rails spec types for `RSpec/DescribeClass`. ([@pirj][])
|
34
|
+
* Fix `FactoryBot/AttributeDefinedStatically` to allow `#traits_for_enum` without a block. ([@harrylewis][])
|
35
|
+
* Improve the performance of `FactoryBot/AttributeDefinedStatically`, `RSpec/InstanceVariable`, `RSpec/LetSetup`, `RSpec/NestedGroups` and `RSpec/ReturnFromStub`. ([@andrykonchin][])
|
36
|
+
|
5
37
|
## 1.40.0 (2020-06-11)
|
6
38
|
|
7
39
|
* Add new `RSpec/VariableName` cop. ([@tejasbubane][])
|
@@ -518,3 +550,8 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
|
518
550
|
[@robotdana]: https://github.com/robotdana
|
519
551
|
[@rolfschmidt]: https://github.com/rolfschmidt
|
520
552
|
[@andrykonchin]: https://github.com/andrykonchin
|
553
|
+
[@harrylewis]: https://github.com/harrylewis
|
554
|
+
[@elliterate]: https://github.com/elliterate
|
555
|
+
[@mlarraz]: https://github.com/mlarraz
|
556
|
+
[@jtannas]: https://github.com/jtannas
|
557
|
+
[@mockdeep]: https://github.com/mockdeep
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# The RuboCop Community Code of Conduct
|
2
|
+
|
3
|
+
**Note:** We have picked the following code of conduct based on [Ruby's own
|
4
|
+
code of conduct](https://www.ruby-lang.org/en/conduct/).
|
5
|
+
|
6
|
+
This document provides a few simple community guidelines for a safe, respectful,
|
7
|
+
productive, and collaborative place for any person who is willing to contribute
|
8
|
+
to the RuboCop community. It applies to all "collaborative spaces", which are
|
9
|
+
defined as community communications channels (such as mailing lists, submitted
|
10
|
+
patches, commit comments, etc.).
|
11
|
+
|
12
|
+
* Participants will be tolerant of opposing views.
|
13
|
+
* Participants must ensure that their language and actions are free of personal
|
14
|
+
attacks and disparaging personal remarks.
|
15
|
+
* When interpreting the words and actions of others, participants should always
|
16
|
+
assume good intentions.
|
17
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
data/config/default.yml
CHANGED
@@ -74,7 +74,7 @@ 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
|
77
|
+
Description: Check that the first argument to the top-level describe is a constant.
|
78
78
|
Enabled: true
|
79
79
|
VersionAdded: '1.0'
|
80
80
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeClass
|
@@ -381,7 +381,7 @@ RSpec/MissingExampleGroupArgument:
|
|
381
381
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MissingExampleGroupArgument
|
382
382
|
|
383
383
|
RSpec/MultipleDescribes:
|
384
|
-
Description: Checks for multiple top
|
384
|
+
Description: Checks for multiple top-level example groups.
|
385
385
|
Enabled: true
|
386
386
|
VersionAdded: '1.0'
|
387
387
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleDescribes
|
@@ -394,6 +394,14 @@ RSpec/MultipleExpectations:
|
|
394
394
|
VersionChanged: '1.21'
|
395
395
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleExpectations
|
396
396
|
|
397
|
+
RSpec/MultipleMemoizedHelpers:
|
398
|
+
Description: Checks if example groups contain too many `let` and `subject` calls.
|
399
|
+
Enabled: true
|
400
|
+
AllowSubject: true
|
401
|
+
Max: 5
|
402
|
+
VersionAdded: '1.43'
|
403
|
+
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers
|
404
|
+
|
397
405
|
RSpec/MultipleSubjects:
|
398
406
|
Description: Checks if an example group defines `subject` multiple times.
|
399
407
|
Enabled: true
|
@@ -558,7 +566,9 @@ RSpec/VariableName:
|
|
558
566
|
SupportedStyles:
|
559
567
|
- snake_case
|
560
568
|
- camelCase
|
569
|
+
IgnoredPatterns: []
|
561
570
|
VersionAdded: '1.40'
|
571
|
+
VersionChanged: '1.43'
|
562
572
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VariableName
|
563
573
|
|
564
574
|
RSpec/VerifiedDoubles:
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -13,16 +13,18 @@ require_relative 'rubocop/rspec/top_level_describe'
|
|
13
13
|
require_relative 'rubocop/rspec/wording'
|
14
14
|
require_relative 'rubocop/rspec/language'
|
15
15
|
require_relative 'rubocop/rspec/language/node_pattern'
|
16
|
+
require_relative 'rubocop/rspec/top_level_group'
|
16
17
|
require_relative 'rubocop/rspec/concept'
|
17
18
|
require_relative 'rubocop/rspec/example_group'
|
18
19
|
require_relative 'rubocop/rspec/example'
|
19
20
|
require_relative 'rubocop/rspec/hook'
|
20
21
|
require_relative 'rubocop/rspec/variable'
|
22
|
+
require_relative 'rubocop/cop/rspec/base'
|
21
23
|
require_relative 'rubocop/cop/rspec/cop'
|
22
24
|
require_relative 'rubocop/rspec/align_let_brace'
|
23
25
|
require_relative 'rubocop/rspec/factory_bot'
|
24
26
|
require_relative 'rubocop/rspec/final_end_location'
|
25
|
-
require_relative 'rubocop/rspec/
|
27
|
+
require_relative 'rubocop/rspec/empty_line_separation'
|
26
28
|
require_relative 'rubocop/rspec/corrector/move_node'
|
27
29
|
|
28
30
|
RuboCop::RSpec::Inject.defaults!
|
@@ -17,36 +17,29 @@ module RuboCop
|
|
17
17
|
# let(:baz) { bar }
|
18
18
|
# let(:a) { b }
|
19
19
|
#
|
20
|
-
class AlignLeftLetBrace <
|
20
|
+
class AlignLeftLetBrace < Base
|
21
|
+
extend AutoCorrector
|
22
|
+
|
21
23
|
MSG = 'Align left let brace'
|
22
24
|
|
23
25
|
def self.autocorrect_incompatible_with
|
24
26
|
[Layout::ExtraSpacing]
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
29
|
+
def on_new_investigation
|
28
30
|
return if processed_source.blank?
|
29
31
|
|
30
|
-
token_aligner
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
32
|
+
token_aligner =
|
33
|
+
RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :begin)
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
token_aligner.offending_tokens.each do |let|
|
36
|
+
add_offense(let.loc.begin) do |corrector|
|
37
|
+
corrector.insert_before(
|
38
|
+
let.loc.begin, token_aligner.indent_for(let)
|
39
|
+
)
|
40
|
+
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def token_aligner
|
47
|
-
@token_aligner ||=
|
48
|
-
RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :begin)
|
49
|
-
end
|
50
43
|
end
|
51
44
|
end
|
52
45
|
end
|
@@ -17,36 +17,29 @@ module RuboCop
|
|
17
17
|
# let(:baz) { bar }
|
18
18
|
# let(:a) { b }
|
19
19
|
#
|
20
|
-
class AlignRightLetBrace <
|
20
|
+
class AlignRightLetBrace < Base
|
21
|
+
extend AutoCorrector
|
22
|
+
|
21
23
|
MSG = 'Align right let brace'
|
22
24
|
|
23
25
|
def self.autocorrect_incompatible_with
|
24
26
|
[Layout::ExtraSpacing]
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
29
|
+
def on_new_investigation
|
28
30
|
return if processed_source.blank?
|
29
31
|
|
30
|
-
token_aligner
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
32
|
+
token_aligner =
|
33
|
+
RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :end)
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
token_aligner.offending_tokens.each do |let|
|
36
|
+
add_offense(let.loc.end) do |corrector|
|
37
|
+
corrector.insert_before(
|
38
|
+
let.loc.end, token_aligner.indent_for(let)
|
39
|
+
)
|
40
|
+
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def token_aligner
|
47
|
-
@token_aligner ||=
|
48
|
-
RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :end)
|
49
|
-
end
|
50
43
|
end
|
51
44
|
end
|
52
45
|
end
|
@@ -0,0 +1,74 @@
|
|
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
|
+
# Invoke the original inherited hook so our cops are recognized
|
33
|
+
def self.inherited(subclass) # rubocop:disable Lint/MissingSuper
|
34
|
+
RuboCop::Cop::Base.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.match?(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
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/rubocop/cop/rspec/be.rb
CHANGED
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
# expect(foo).to be 1.0
|
20
20
|
# expect(foo).to be(true)
|
21
21
|
#
|
22
|
-
class Be <
|
22
|
+
class Be < Base
|
23
23
|
MSG = 'Don\'t use `be` without an argument.'
|
24
24
|
|
25
25
|
def_node_matcher :be_without_args, <<-PATTERN
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
|
29
29
|
def on_send(node)
|
30
30
|
be_without_args(node) do |matcher|
|
31
|
-
add_offense(matcher
|
31
|
+
add_offense(matcher.loc.selector)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -35,7 +35,9 @@ module RuboCop
|
|
35
35
|
# necessarily the same type as `b` since the `#==` operator can
|
36
36
|
# coerce objects for comparison.
|
37
37
|
#
|
38
|
-
class BeEql <
|
38
|
+
class BeEql < Base
|
39
|
+
extend AutoCorrector
|
40
|
+
|
39
41
|
MSG = 'Prefer `be` over `eql`.'
|
40
42
|
|
41
43
|
def_node_matcher :eql_type_with_identity, <<-PATTERN
|
@@ -44,13 +46,11 @@ module RuboCop
|
|
44
46
|
|
45
47
|
def on_send(node)
|
46
48
|
eql_type_with_identity(node) do |eql|
|
47
|
-
add_offense(eql
|
49
|
+
add_offense(eql.loc.selector) do |corrector|
|
50
|
+
corrector.replace(eql.loc.selector, 'be')
|
51
|
+
end
|
48
52
|
end
|
49
53
|
end
|
50
|
-
|
51
|
-
def autocorrect(node)
|
52
|
-
->(corrector) { corrector.replace(node.loc.selector, 'be') }
|
53
|
-
end
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -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,9 @@ 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
|
+
extend AutoCorrector
|
28
|
+
|
27
29
|
MSG = 'Do not set an RSpec expectation on `current_path` in ' \
|
28
30
|
'Capybara feature specs - instead, use the ' \
|
29
31
|
'`have_current_path` matcher on `page`'
|
@@ -47,30 +49,30 @@ module RuboCop
|
|
47
49
|
|
48
50
|
def on_send(node)
|
49
51
|
expectation_set_on_current_path(node) do
|
50
|
-
add_offense(node
|
52
|
+
add_offense(node.loc.selector) do |corrector|
|
53
|
+
next unless node.chained?
|
54
|
+
|
55
|
+
autocorrect(corrector, node)
|
56
|
+
end
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
54
|
-
|
55
|
-
lambda do |corrector|
|
56
|
-
return unless node.chained?
|
60
|
+
private
|
57
61
|
|
58
|
-
|
59
|
-
|
60
|
-
|
62
|
+
def autocorrect(corrector, node)
|
63
|
+
as_is_matcher(node.parent) do |to_sym, matcher_node|
|
64
|
+
rewrite_expectation(corrector, node, to_sym, matcher_node)
|
65
|
+
end
|
61
66
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
67
|
+
regexp_str_matcher(node.parent) do |to_sym, matcher_node, regexp|
|
68
|
+
rewrite_expectation(corrector, node, to_sym, matcher_node)
|
69
|
+
convert_regexp_str_to_literal(corrector, matcher_node, regexp)
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
69
|
-
private
|
70
|
-
|
71
73
|
def rewrite_expectation(corrector, node, to_symbol, matcher_node)
|
72
74
|
current_path_node = node.first_argument
|
73
|
-
corrector.replace(current_path_node
|
75
|
+
corrector.replace(current_path_node, 'page')
|
74
76
|
corrector.replace(node.parent.loc.selector, 'to')
|
75
77
|
matcher_method = if to_symbol == :to
|
76
78
|
'have_current_path'
|
@@ -84,7 +86,7 @@ module RuboCop
|
|
84
86
|
def convert_regexp_str_to_literal(corrector, matcher_node, regexp_str)
|
85
87
|
str_node = matcher_node.first_argument
|
86
88
|
regexp_expr = Regexp.new(regexp_str).inspect
|
87
|
-
corrector.replace(str_node
|
89
|
+
corrector.replace(str_node, regexp_expr)
|
88
90
|
end
|
89
91
|
|
90
92
|
# `have_current_path` with no options will include the querystring
|
@@ -97,7 +99,7 @@ module RuboCop
|
|
97
99
|
return if %i[regexp str].include?(expectation_last_child.type)
|
98
100
|
|
99
101
|
corrector.insert_after(
|
100
|
-
expectation_last_child
|
102
|
+
expectation_last_child,
|
101
103
|
', ignore_query: true'
|
102
104
|
)
|
103
105
|
end
|