-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose 'with default RSpec/Language config' to consumers
This helper is essential for anyone writing their own RSpec cops based on `RuboCop::Cop::RSpec::Base`, because it now requires a minimal config to even run the cop. The wordy file name is because the RuboCop gem already defines `rubocop/rspec/shared_contexts`, and we don't want to shadow that. This means that consumers of this library who want to write a spec for a cop based on `RuboCop::Cop::RSpec::Base` will need something like this in `spec/spec_helper.rb`: require 'rubocop/rspec/shared_contexts/default_rspec_language_config_context' RSpec.config do |config| # ... # Add metadata as appropriate to ensure this only happens for RSpec # cop specs config.include_context 'with default RSpec/Language config' end
- Loading branch information
Showing
5 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
= Development | ||
|
||
This page describes considerations when developing RSpec-specific cops. It is intended to be a complement to the general https://docs.rubocop.org/rubocop/development.html[RuboCop development documentation]. | ||
|
||
== Base class | ||
|
||
The `RuboCop::Cop::RSpec::Base` class includes convenient https://docs.rubocop.org/rubocop-ast/node_pattern.html[node pattern DSL] matchers that will automatically account for any xref:usage.adoc#rspec-dsl-configuration[custom RSpec DSL configuration]. | ||
|
||
For example, if the project defines https://github.com/test-prof/test-prof/blob/master/docs/recipes/let_it_be.md[`let_it_be`] as a `Helper`, then all cops will find `let_it_be` when using the `let?` matcher. | ||
|
||
== Writing specs | ||
|
||
When working on RSpec-specific cops, ensure that the https://github.com/rubocop/rubocop-rspec/blob/master/config/default.yml[default language config] is loaded for all RSpec specs. For example: | ||
|
||
[source,ruby] | ||
---- | ||
require 'rubocop/rspec/shared_contexts/default_rspec_language_config_context' | ||
RSpec.config do |config| | ||
# Set metadata on all cop specs | ||
config.define_derived_metadata(file_path: %r{/spec/rubocop/cop/}) do |meta| | ||
meta[:type] = :cop_spec | ||
end | ||
# Include RuboCop's config shared context for all cop specs | ||
config.define_derived_metadata(type: :cop_spec) do |meta| | ||
meta[:config] = true | ||
end | ||
config.include_context 'with default RSpec/Language config', :config | ||
end | ||
---- |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters