Class: Solargraph::Rspec::TestHelpers

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/rspec/test_helpers.rb

Defined Under Namespace

Classes: GemHelpers

Constant Summary collapse

GEM_HELPERS =
GemHelpers.new(
    required_gems: %w[rspec],
    helper_modules: %w[RSpec::Matchers]
  ),
  # https://github.com/rspec/rspec-mocks
  GemHelpers.new(
    required_gems: %w[rspec-mocks],
    helper_modules: %w[RSpec::Mocks::ExampleMethods]
  ),
  # @see https://github.com/rspec/rspec-rails#what-tests-should-i-write
  # @see https://github.com/rspec/rspec-rails#helpful-rails-matchers
  GemHelpers.new(
    required_gems: %w[rspec-rails actionmailer activesupport activerecord],
    helper_modules: [
      'RSpec::Rails::Matchers',
      'ActionController::TestCase::Behavior',
      'ActionMailer::TestCase::Behavior',
      'ActiveSupport::Testing::Assertions',
      'ActiveSupport::Testing::TimeHelpers',
      'ActiveSupport::Testing::FileFixtures',
      'ActiveRecord::TestFixtures',
      'ActionDispatch::Integration::Runner',
      'ActionDispatch::Routing::UrlFor',
      'ActionController::TemplateAssertions'
    ]
  ),
  # @see https://matchers.shoulda.io/docs/v6.2.0/#matchers
  GemHelpers.new(
    required_gems: %w[shoulda-matchers],
    helper_modules: [
      'Shoulda::Matchers::ActiveModel',
      'Shoulda::Matchers::ActiveRecord',
      'Shoulda::Matchers::ActionController',
      'Shoulda::Matchers::Routing'
    ]
  ),
  # @see https://github.com/wspurgin/rspec-sidekiq#matchers
  GemHelpers.new(
    required_gems: %w[rspec-sidekiq],
    helper_modules: %w[RSpec::Sidekiq::Matchers]
  ),
  # @see https://github.com/bblimke/webmock#examples
  GemHelpers.new(
    required_gems: %w[webmock],
    helper_modules: %w[WebMock::API WebMock::Matchers]
  ),
  # @see https://github.com/brooklynDev/airborne
  GemHelpers.new(
    required_gems: %w[airborne],
    helper_modules: %w[Airborne]
  )
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#helper_modulesArray<String> (readonly)

Returns:

  • (Array<String>)


# File 'lib/solargraph/rspec/test_helpers.rb', line 7

#required_gemsArray<String> (readonly)

Returns:

  • (Array<String>)


# File 'lib/solargraph/rspec/test_helpers.rb', line 7

Class Method Details

.gem_namesString

Returns:

  • (String)


15
16
17
# File 'lib/solargraph/rspec/test_helpers.rb', line 15

def gem_names
  GEM_HELPERS.flat_map(&:required_gems)
end

.helper_module_namesArray<String>

Returns:

  • (Array<String>)


20
21
22
# File 'lib/solargraph/rspec/test_helpers.rb', line 20

def helper_module_names
  GEM_HELPERS.flat_map(&:helper_modules)
end

.include_helper_pins(root_example_group_namespace_pin:) ⇒ Array<Pin::Reference::Include>

Parameters:

  • root_example_group_namespace_pin (Pin::Namespace)

Returns:

  • (Array<Pin::Reference::Include>)


26
27
28
29
30
31
32
33
34
35
# File 'lib/solargraph/rspec/test_helpers.rb', line 26

def include_helper_pins(root_example_group_namespace_pin:)
  Solargraph.logger.debug "[RSpec] adding helper modules #{helper_module_names}"
  helper_module_names.map do |helper_module|
    PinFactory.build_module_include(
      root_example_group_namespace_pin,
      helper_module,
      root_example_group_namespace_pin.location
    )
  end
end