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
79 80 81 |
# File 'lib/rubocop/cop/rspec/leaky_local_variable.rb', line 79 def self.joining_forces VariableForce end |
Instance Method Details
#after_leaving_scope(scope, _variable_table) ⇒ Object
83 84 85 |
# File 'lib/rubocop/cop/rspec/leaky_local_variable.rb', line 83 def after_leaving_scope(scope, _variable_table) scope.variables.each_value { |variable| check_references(variable) } end |
#example_method?(node) ⇒ Object
70 71 72 |
# File 'lib/rubocop/cop/rspec/leaky_local_variable.rb', line 70 def_node_matcher :example_method?, "(send nil? #Examples.all _)\n" |
#includes_method?(node) ⇒ Object
75 76 77 |
# File 'lib/rubocop/cop/rspec/leaky_local_variable.rb', line 75 def_node_matcher :includes_method?, "(send nil? #Includes.all ...)\n" |