Class: RuboCop::Cop::RSpec::LeakyLocalVariable
- Defined in:
- lib/rubocop/cop/rspec/leaky_local_variable.rb
Overview
Checks for local variables from outer scopes used inside examples.
Local variables assigned outside an example but used within it act as shared state, which can make tests non-deterministic.
Constant Summary collapse
- MSG =
'Do not use local variables defined outside of ' \ 'examples inside of them.'
Class Method Summary collapse
Instance Method Summary collapse
- #after_leaving_scope(scope, _variable_table) ⇒ Object
- #example_method?(node) ⇒ Object
- #includes_method?(node) ⇒ Object
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?
Class Method Details
.joining_forces ⇒ Object
86 87 88 |
# File 'lib/rubocop/cop/rspec/leaky_local_variable.rb', line 86 def self.joining_forces VariableForce end |
Instance Method Details
#after_leaving_scope(scope, _variable_table) ⇒ Object
90 91 92 |
# File 'lib/rubocop/cop/rspec/leaky_local_variable.rb', line 90 def after_leaving_scope(scope, _variable_table) scope.variables.each_value { |variable| check_references(variable) } end |
#example_method?(node) ⇒ Object
77 78 79 |
# File 'lib/rubocop/cop/rspec/leaky_local_variable.rb', line 77 def_node_matcher :example_method?, "(send nil? #Examples.all _)\n" |
#includes_method?(node) ⇒ Object
82 83 84 |
# File 'lib/rubocop/cop/rspec/leaky_local_variable.rb', line 82 def_node_matcher :includes_method?, "(send nil? #Includes.all ...)\n" |