Skip to content

Commit f663fdc

Browse files
committed
Fix inherit_mode for third-party gems
fixes #1126 See palkan/action_policy#103 (comment) If a third-party gem, e.g. `action_policy`, defines their `config/default.yml` and supplements to the default RSpec DSL that we provide in our `config/default.yml`, `rubocop`'s behaviour is to actually override the configuration, as `inherit_mode` is `override` for lists by default. RuboCop has recently [fixed the problem with ignored `inherit_mode`](rubocop/rubocop#9952) and we've [bumped to use `rubocop` version that includes the fix](#1181), but we haven't adjusted our `config/default.yml` to merge by default. This is causing both user project RSpec DSL configuration and third-party gem RSpec DSL configuration to override our default, rendering our cops blind. ### Example A new project ```ruby # Gemfile source 'https://rubygems.org' gem 'action_policy' gem 'rubocop-rspec' ``` ```yml # .rubocop.yml require: - rubocop-rspec inherit_gem: action_policy: config/rubocop-rspec.yml ``` ```ruby # spec/a_spec.rb RSpec.describe 'A' do it_behaves_like 'a' it_behaves_like 'a' describe_rule :show? do succeed 'when post is published' succeed 'when post is published' end end ``` Ideally, both the duplicated `it_behaves_like` and `succeed` should be detected. However, `action_policy`'s `Includes/Examples` setting overrides ours, and `it_behaves_like` disappears from this list. As a result, `rubocop` only detects the duplication of `succeed`, but not of `it_behaves_like`.
1 parent d73d80b commit f663fdc

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Master (Unreleased)
44

5+
* Fix merging RSpec DSL configuration from third-party gems. ([@pirj][])
6+
57
## 2.5.0 (2021-09-21)
68

79
* Declare autocorrect as unsafe for `ExpectChange`. ([@francois-ferrandis][])

config/default.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,20 @@ RSpec:
55
- "**/*_spec.rb"
66
- "**/spec/**/*"
77
Language:
8+
inherit_mode:
9+
merge:
10+
- Expectations
11+
- Helpers
12+
- Hooks
13+
- HookScopes
14+
- Runners
15+
- Subjects
816
ExampleGroups:
17+
inherit_mode:
18+
merge:
19+
- Regular
20+
- Skipped
21+
- Focused
922
Regular:
1023
- describe
1124
- context
@@ -20,6 +33,12 @@ RSpec:
2033
- fcontext
2134
- ffeature
2235
Examples:
36+
inherit_mode:
37+
merge:
38+
- Regular
39+
- Skipped
40+
- Focused
41+
- Pending
2342
Regular:
2443
- it
2544
- specify
@@ -62,6 +81,10 @@ RSpec:
6281
- all
6382
- suite
6483
Includes:
84+
inherit_mode:
85+
merge:
86+
- Examples
87+
- Context
6588
Examples:
6689
- it_behaves_like
6790
- it_should_behave_like
@@ -73,6 +96,10 @@ RSpec:
7396
- to_not
7497
- not_to
7598
SharedGroups:
99+
inherit_mode:
100+
merge:
101+
- Examples
102+
- Context
76103
Examples:
77104
- shared_examples
78105
- shared_examples_for

docs/modules/ROOT/pages/third_party_rspec_syntax_extensions.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ RuboCop https://docs.rubocop.org/rubocop/configuration.html#inheriting-configura
88

99
== Packaging configuration for RuboCop RSpec
1010

11+
NOTE: Due to a [bug](https://github.com/rubocop/rubocop-rspec/issues/1126), this feature doesn't work properly for `rubocop-rspec` 2.5.0 and earlier versions.
12+
1113
For a third-party gem, it's sufficient to follow three steps:
1214

1315
1. Provide a configuration file (e.g. `.rubocop_rspec_alias_config.yml` or `config/rubocop-rspec.yml`).

0 commit comments

Comments
 (0)