Module: TurboRspec

Defined in:
lib/turbo_rspec.rb,
lib/turbo_rspec/helpers.rb,
lib/turbo_rspec/version.rb,
lib/turbo_rspec/matchers.rb,
lib/turbo_rspec/assertions.rb,
lib/turbo_rspec/configuration.rb,
lib/turbo_rspec/capybara/matchers.rb,
lib/turbo_rspec/matchers/have_turbo_frame.rb,
lib/turbo_rspec/matchers/have_turbo_stream.rb,
lib/turbo_rspec/matchers/have_turbo_streams.rb,
lib/generators/turbo_rspec/install_generator.rb,
lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb,
lib/turbo_rspec/capybara/matchers/have_turbo_stream_tag.rb,
lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb

Overview

TurboRspec provides RSpec matchers and Minitest assertions for turbo-rails.

Examples:

Configure auto-include

TurboRspec.configure do |config|
  config.auto_include = false
end

Defined Under Namespace

Modules: Assertions, Capybara, Generators, Helpers, Matchers Classes: Configuration, Error

Constant Summary collapse

BUILTIN_ACTIONS =

Built-in Turbo stream action names.

%w[append prepend replace update remove before after refresh morph].freeze
VERSION =
"1.2.0"

Class Method Summary collapse

Class Method Details

.configurationConfiguration

Returns the global configuration instance.

Returns:



41
42
43
# File 'lib/turbo_rspec.rb', line 41

def configuration
  @configuration ||= Configuration.new
end

.configure {|config| ... } ⇒ void

This method returns an undefined value.

Yields the configuration object for customization.

Examples:

TurboRspec.configure do |config|
  config.auto_include = false
end

Yield Parameters:



34
35
36
# File 'lib/turbo_rspec.rb', line 34

def configure
  yield configuration
end

.install_rspec_integration(config) ⇒ void

This method returns an undefined value.

Installs RSpec integration — includes matchers and helpers into the appropriate example groups. Called automatically when RSpec is present.

Parameters:

  • config (RSpec::Core::Configuration)


75
76
77
78
79
80
81
82
83
84
85
# File 'lib/turbo_rspec.rb', line 75

def install_rspec_integration(config)
  return unless configuration.auto_include && Gem.loaded_specs.key?("turbo-rails")
  config.include Matchers, type: :request
  config.include Matchers, type: :controller
  config.include Helpers, type: :request
  config.include Helpers, type: :controller
  if Gem.loaded_specs.key?("capybara")
    config.include Capybara::Matchers, type: :system
    config.include Capybara::Matchers, type: :feature
  end
end

.known_actionsArray<String>

Returns all known stream action names (built-in + registered custom).

Returns:

  • (Array<String>)


66
67
68
# File 'lib/turbo_rspec.rb', line 66

def known_actions
  BUILTIN_ACTIONS + configuration.custom_actions
end

.register_action(*actions) ⇒ void

This method returns an undefined value.

Registers one or more custom Turbo stream action names so that +have_turbo_stream.with_action(:name)+ does not raise +ArgumentError+.

Examples:

TurboRspec.register_action(:sparkle, :highlight)

Parameters:

  • actions (Array<Symbol, String>)


59
60
61
# File 'lib/turbo_rspec.rb', line 59

def register_action(*actions)
  configuration.custom_actions |= actions.map(&:to_s)
end

.reset_configuration!void

This method returns an undefined value.

Resets configuration to defaults. Primarily for use in test suites.



48
49
50
# File 'lib/turbo_rspec.rb', line 48

def reset_configuration!
  @configuration = Configuration.new
end