Class: RuboCop::Cop::Vicenzo::RSpec::TopLevelContext
- Inherits:
-
RSpec::Base
- Object
- RSpec::Base
- RuboCop::Cop::Vicenzo::RSpec::TopLevelContext
- Includes:
- TopLevelDefinition
- Defined in:
- lib/rubocop/cop/vicenzo/rspec/top_level_context.rb
Overview
A context declared straight inside the top-level example group is a scenario for the whole file. Nest it in the group whose behaviour it is a scenario of.
A context answers "under which circumstances?", and the question only means something once a behaviour has been named. Declared at the root, the scenario applies to every example in the file at once - the same overreach a root subject or a root let has, since the premises the context declares are handed to everything written under it later.
It is also how the file loses the describe it never had: the first behaviour goes under
context 'when ...', the second one needs the same circumstances worded slightly differently,
and what should have been two groups naming two behaviours becomes a tree of scenarios naming
none.
Constant Summary collapse
- MSG =
'This context is declared in the top-level example group, so it is a scenario for every ' \ 'example in the file. Nest it in the group whose behaviour it is a scenario of.'
- CONTEXTS =
i[context fcontext xcontext].freeze
Constants included from PremiseTracking
Instance Method Summary collapse
Methods included from TopLevelDefinition
Methods included from PremiseTracking
#premise_name, #root_receiver_name
Instance Method Details
#context_definition?(node) ⇒ Object
51 52 53 |
# File 'lib/rubocop/cop/vicenzo/rspec/top_level_context.rb', line 51 def_node_matcher :context_definition?, "(any_block (send nil? {\#{CONTEXTS.map(&:inspect).join(' ')}} ...) ...)\n" |