Class: Solargraph::Rspec::Correctors::ExampleAndHookBlocksBindingCorrector

Inherits:
Base
  • Object
show all
Defined in:
lib/solargraph/rspec/correctors/example_and_hook_blocks_binding_corrector.rb

Overview

RSpec executes example and hook blocks in the context of the example group (ie. describe blocks). This correctors sets the right bindings to those blocks.

Instance Attribute Summary

Attributes inherited from Base

#added_pins, #namespace_pins, #rspec_walker

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Solargraph::Rspec::Correctors::Base

Instance Method Details

#correct(source_map) ⇒ void

This method returns an undefined value.

Parameters:

  • source_map (Solargraph::SourceMap)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/solargraph/rspec/correctors/example_and_hook_blocks_binding_corrector.rb', line 13

def correct(source_map)
  rspec_walker.on_example_block do |location_range|
    bind_closest_namespace(location_range, source_map)
  end

  rspec_walker.on_hook_block do |location_range|
    bind_closest_namespace(location_range, source_map)
  end

  rspec_walker.on_let_method do |_method_name, location_range|
    bind_closest_namespace(location_range, source_map)
  end

  rspec_walker.on_blocks_in_examples do |location_range|
    bind_closest_namespace(location_range, source_map)
  end

  rspec_walker.on_subject do |_method_name, location_range|
    bind_closest_namespace(location_range, source_map)
  end
end