Skip to content

Commit 5e5eeba

Browse files
authored
Merge pull request #1097 from rubocop-hq/add-doc-how-to-configure-rspec-aliases-in-third-party-gem
Add docs on configuring RSpec aliases from gems
2 parents 07ff530 + 412227a commit 5e5eeba

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ rubocop-rspec is available on Code Climate as part of the rubocop engine. [Learn
7171

7272
## Documentation
7373

74-
You can read more about RuboCop-RSpec in its [official manual](https://docs.rubocop.org/rubocop-rspec).
74+
You can read more about RuboCop RSpec in its [official manual](https://docs.rubocop.org/rubocop-rspec).
7575

7676
## The Cops
7777

docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* xref:usage.adoc[Usage]
44
* xref:cops.adoc[Cops]
55
* xref:upgrade_to_version_2.adoc[Upgrade to 2.x]
6+
* xref:third_party_rspec_extensions.adoc[RSpec syntax extensions in third-party gems]
67
* Cops Documentation
78
** xref:cops_capybara.adoc[Capybara]
89
** xref:cops_factorybot.adoc[FactoryBot]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
= RSpec syntax extensions in third-party gems
2+
3+
Some gems, e.g. https://github.com/CanCanCommunity/cancancan[cancancan], https://github.com/palkan/action_policy[action_policy] and https://github.com/varvet/pundit[pundit] provide their own extensions and aliases to RSpec syntax. Also, RSpec extensions like https://github.com/palkan/test-prof[test-prof], https://github.com/rspec/rspec-its[rspec-its] and https://github.com/zverok/saharspec#its-addons[saharspec] do.
4+
5+
By default, RuboCop RSpec is not aware of those syntax extensions, and does not intend to gather all of them in the default configuration file.
6+
It is possible for the gems to provide configuration for RuboCop RSpec to allow proper detection of RSpec elements.
7+
RuboCop https://docs.rubocop.org/rubocop/configuration.html#inheriting-configuration-from-a-dependency-gem[provides third-party gems with an ability to configure RuboCop].
8+
9+
== Packaging configuration for RuboCop RSpec
10+
11+
For a third-party gem, it's sufficient to follow three steps:
12+
13+
1. Provide a configuration file (e.g. `.rubocop_rspec_alias_config.yml` or `config/rubocop-rspec.yml`).
14+
Please check with the xref:usage.adoc#rspec-dsl-configuration[RSpec DSL configuration] how different elements of RSpec syntax can be configured.
15+
16+
2. Add a section to their documentation how users can benefit from using RuboCop RSpec with full detection of their syntax extensions.
17+
Example:
18+
19+
## Usage with RuboCop RSpec
20+
Please add the following to your `.rubocop.yml` to make RuboCop RSpec aware of our cool syntax extensions:
21+
inherit_gem:
22+
third-party-gem: .rubocop_rspec_alias_config.yml
23+
24+
3. Include the configuration file to their package by updating their `gemspec`’s `spec.files` to include the aforementioned configuration file.
25+
26+
See pull requests: https://github.com/test-prof/test-prof/pull/199[test-prof], and https://github.com/palkan/action_policy/pull/138[action_policy] for a less trivial example.

lib/rubocop/rspec/node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module RuboCop
44
module RSpec
5-
# RuboCop-RSpec specific extensions of RuboCop::AST::Node
5+
# RuboCop RSpec specific extensions of RuboCop::AST::Node
66
module Node
77
# In various cops we want to regard const as literal althought it's not
88
# strictly literal.

0 commit comments

Comments
 (0)