Class: Solargraph::Rspec::Convention

Inherits:
Convention::Base
  • Object
show all
Defined in:
lib/solargraph/rspec/convention.rb

Overview

Provides completion for RSpec DSL and helper methods.

- `describe` and `context` blocks
- `let` and `let!` methods
- `subject` method
- `described_class` method
- `it` method with correct binding
- `RSpec::Matchers` module

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configConfig

Returns:



72
73
74
# File 'lib/solargraph/rspec/convention.rb', line 72

def self.config
  @config ||= Config.new
end

.valid_filename?(filename) ⇒ Boolean

Parameters:

  • filename (String)

Returns:

  • (Boolean)


78
79
80
# File 'lib/solargraph/rspec/convention.rb', line 78

def self.valid_filename?(filename)
  filename.include?('spec/')
end

Instance Method Details

#global(_yard_map) ⇒ Environ

Parameters:

  • yard_map (YardMap)

Returns:

  • (Environ)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/solargraph/rspec/convention.rb', line 84

def global(_yard_map)
  pins = []
  pins += include_helper_pins

  if pins.any?
    Solargraph.logger.debug(
      "[RSpec] added global pins #{pins.map(&:inspect)}"
    )
  end

  Environ.new(pins: pins)
rescue StandardError => e
  raise e if ENV['SOLARGRAPH_DEBUG']

  Solargraph.logger.warn(
    "[RSpec] Error processing global pins: #{e.message}\n#{e.backtrace.join("\n")}"
  )
  EMPTY_ENVIRON
end

#local(source_map) ⇒ Environ

Parameters:

  • source_map (SourceMap)

Returns:

  • (Environ)


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/solargraph/rspec/convention.rb', line 106

def local(source_map)
  Solargraph.logger.debug "[RSpec] processing #{source_map.filename}"

  return EMPTY_ENVIRON unless self.class.valid_filename?(source_map.filename)

  # @type [Array<Pin::Base>]
  pins = []
  # @type [Array<Pin::Namespace>]
  namespace_pins = []

  rspec_walker = SpecWalker.new(source_map: source_map, config: config)

  CORRECTOR_CLASSES.each do |corrector_class|
    corrector_class.new(
      namespace_pins: namespace_pins,
      rspec_walker: rspec_walker,
      added_pins: pins
    ).correct(source_map)
  end

  rspec_walker.walk!
  pins += namespace_pins

  if pins.any?
    Solargraph.logger.debug(
      "[RSpec] added #{pins.map(&:inspect)} to #{source_map.filename}"
    )
  end

  Environ.new(requires: ['rspec'], pins: pins)
rescue StandardError => e
  raise e if ENV['SOLARGRAPH_DEBUG']

  Solargraph.logger.warn(
    "[RSpec] Error processing #{source_map.filename}: #{e.message}\n#{e.backtrace.join("\n")}"
  )
  EMPTY_ENVIRON
end