Class: RuboCop::Cop::RSpec::IncludeExamples
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rspec/include_examples.rb
Overview
Checks for usage of ‘include_examples`.
‘include_examples`, unlike `it_behaves_like`, does not create its own context. As such, using `subject`, `let`, `before`/`after`, etc. within shared examples included with `include_examples` can have unexpected behavior and side effects.
Prefer using ‘it_behaves_like` instead.
Constant Summary collapse
- MSG =
'Prefer `it_behaves_like` over `include_examples`.'- RESTRICT_ON_SEND =
%i[include_examples].freeze
Instance Method Summary collapse
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language
#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#on_send(node) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/rubocop/cop/rspec/include_examples.rb', line 80 def on_send(node) selector = node.loc.selector add_offense(selector) do |corrector| corrector.replace(selector, 'it_behaves_like') end end |