Class: RuboCop::Cop::Vicenzo::RSpec::TopLevelHook
- Inherits:
-
RSpec::Base
- Object
- RSpec::Base
- RuboCop::Cop::Vicenzo::RSpec::TopLevelHook
- Includes:
- TopLevelDefinition
- Defined in:
- lib/rubocop/cop/vicenzo/rspec/top_level_hook.rb
Overview
A hook declared straight inside the top-level example group runs for every example in the file. Declare it in the group whose examples need it.
A hook is a premise like any other - it just builds the state through side effects instead of a name. Declared at the root it reaches every example, including the ones written later that never asked for that state, and the group that needs the state built differently can only undo it, override it, or work around it.
It is also the escape hatch left open once the root cannot hold a subject or a let any
more: the premise stops being declared and starts being performed, which is harder to read and
invisible to the cops that watch definitions. Vicenzo/RSpec/TopLevelSubject and
Vicenzo/RSpec/TopLevelLet close the front door; this one closes the back.
Constant Summary collapse
- MSG =
'Hook `%<name>s` is declared in the top-level example group, so it runs for every ' \ 'example in the file. Declare it in the group whose examples need it.'