Skip to content

Commit cc41715

Browse files
committed
fixup! Add RSpec DSL configuration docs
1 parent 1e499d2 commit cc41715

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/modules/ROOT/pages/usage.adoc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,59 @@ require:
2222
Now you can run `rubocop` and it will automatically load the RuboCop RSpec
2323
cops together with the standard cops.
2424

25+
=== RSpec DSL configuration
26+
27+
In case you https://github.com/rspec/rspec-core/blob/b0d0843a285693c64cdbe0c85726db155b46047e/lib/rspec/core/configuration.rb#L1122[define aliases for RSpec DSL], i.e. examples, example groups, hooks, or include example statements, you need to properly configure it so those elements are properly detected by RuboCop-RSpec.
28+
29+
[source,ruby]
30+
----
31+
# spec/spec_helper.rb
32+
alias_example_group_to
33+
RSpec.configure do |c|
34+
c.alias_example_group_to :detail, :detailed => true
35+
end
36+
37+
# spec/detail_spec.rb
38+
RSpec.detail "a detail" do
39+
it "can do some less important stuff" do
40+
end
41+
end
42+
----
43+
44+
[source,yaml]
45+
----
46+
# .rubocop.yml
47+
RSpec:
48+
Language:
49+
ExampleGroups:
50+
Regular:
51+
- detail
52+
----
53+
54+
Some libraries extensively define RSpec DSL aliases (e.g. Pundit, ActionPolicy) or augment existing elements providing the same semantics (e.g. `let_it_be` from `test-prof`)
55+
Those libraries can provide necessary configuration, but won't necessarily do so.
56+
If they do, their README will mention that you have to explicitly require their configuration from your `.rubocop.yml` file.
57+
58+
[source,yaml]
59+
----
60+
# .rubocop.yml
61+
62+
require:
63+
- rubocop-rspec
64+
- test-prof
65+
66+
# or
67+
68+
RSpec:
69+
Language:
70+
Helpers:
71+
- let_it_be
72+
----
73+
74+
NOTE: the default merge mode is to inherit, so you won't remove any of the default settings.
75+
76+
RuboCop-RSpec's https://github.com/rubocop-hq/rubocop-rspec/blob/a43424527c09fae2e6ddb133f4b2988f6c46bb2e/config/default.yml#L6[default configuration] is a good source of information on what can be configured.
77+
2578
== Command line
2679

2780
[source,bash]

0 commit comments

Comments
 (0)