Skip to content

Commit

Permalink
fixup! Add RSpec DSL configuration docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Nov 3, 2020
1 parent 1e499d2 commit cc41715
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions docs/modules/ROOT/pages/usage.adoc
Expand Up @@ -22,6 +22,59 @@ require:
Now you can run `rubocop` and it will automatically load the RuboCop RSpec
cops together with the standard cops.

=== RSpec DSL configuration

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.

[source,ruby]
----
# spec/spec_helper.rb
alias_example_group_to
RSpec.configure do |c|
c.alias_example_group_to :detail, :detailed => true
end
# spec/detail_spec.rb
RSpec.detail "a detail" do
it "can do some less important stuff" do
end
end
----

[source,yaml]
----
# .rubocop.yml
RSpec:
Language:
ExampleGroups:
Regular:
- detail
----

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`)
Those libraries can provide necessary configuration, but won't necessarily do so.
If they do, their README will mention that you have to explicitly require their configuration from your `.rubocop.yml` file.

[source,yaml]
----
# .rubocop.yml
require:
- rubocop-rspec
- test-prof
# or
RSpec:
Language:
Helpers:
- let_it_be
----

NOTE: the default merge mode is to inherit, so you won't remove any of the default settings.

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.

== Command line

[source,bash]
Expand Down

0 comments on commit cc41715

Please sign in to comment.