Class: RuboCop::Cop::RSpec::Dialect
- Includes:
- MethodPreference
- Defined in:
- lib/rubocop/cop/rspec/dialect.rb
Overview
This cop enforces custom RSpec dialects.
A dialect can be based on the following RSpec methods:
-
describe, context, feature, example_group
-
xdescribe, xcontext, xfeature
-
fdescribe, fcontext, ffeature
-
shared_examples, shared_examples_for, shared_context
-
it, specify, example, scenario, its
-
fit, fspecify, fexample, fscenario, focus
-
xit, xspecify, xexample, xscenario, skip
-
pending
-
prepend_before, before, append_before,
-
around
-
prepend_after, after, append_after
-
let, let!
-
subject, subject!
-
expect, is_expected, expect_any_instance_of
By default all of the RSpec methods and aliases are allowed. By setting a config like:
RSpec/Dialect:
PreferredMethods:
context: describe
You can expect the following behavior:
Constant Summary collapse
- MSG =
'Prefer `%<prefer>s` over `%<current>s`.'
Constants inherited from Cop
Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE
Constants included from RSpec::Language
RSpec::Language::ALL, RSpec::Language::RSPEC
Instance Method Summary collapse
Methods inherited from Cop
Instance Method Details
#autocorrect(node) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/rubocop/cop/rspec/dialect.rb', line 58 def autocorrect(node) lambda do |corrector| current = node.loc.selector preferred = preferred_method(current.source) corrector.replace(current, preferred) end end |
#on_send(node) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/rubocop/cop/rspec/dialect.rb', line 51 def on_send(node) return unless rspec_method?(node) return unless preferred_methods[node.method_name] add_offense(node) end |