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

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

Overview

Sets the correct namespace binding for example group blocks (it, example, etc.) and hook blocks (before, after, around)

Instance Attribute Summary

Attributes inherited from WalkerBase

#namespace_pins, #rspec_walker

Attributes inherited from Base

#namespace_pins

Instance Method Summary collapse

Methods inherited from WalkerBase

#initialize

Methods inherited from Base

#initialize

Constructor Details

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

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
34
35
36
37
38
39
40
41
42
43
# 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)

    yield [] if block_given?
  end

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

    yield [] if block_given?
  end

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

    yield [] if block_given?
  end

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

    yield [] if block_given?
  end

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

    yield [] if block_given?
  end
end