Class: TurboRspec::Capybara::Matchers::HaveStimulusController

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_rspec/capybara/matchers/have_stimulus_controller.rb

Overview

Capybara matcher asserting that an element with the given Stimulus controller is present on the page (+data-controller+ contains the name as a space-separated token).

Examples:

expect(page).to have_stimulus_controller("hello")
expect(page).not_to have_stimulus_controller("missing")

Instance Method Summary collapse

Constructor Details

#initialize(controller_name) ⇒ HaveStimulusController

Returns a new instance of HaveStimulusController.



14
15
16
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_controller.rb', line 14

def initialize(controller_name)
  @controller_name = controller_name.to_s
end

Instance Method Details

#descriptionObject



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

def description
  "have Stimulus controller #{@controller_name.inspect}"
end

#does_not_match?(page_or_node) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_controller.rb', line 22

def does_not_match?(page_or_node)
  page_or_node.has_no_css?(selector, wait: 0)
end

#failure_messageObject



26
27
28
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_controller.rb', line 26

def failure_message
  "expected page to have Stimulus controller #{@controller_name.inspect}"
end

#failure_message_when_negatedObject



30
31
32
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_controller.rb', line 30

def failure_message_when_negated
  "expected page not to have Stimulus controller #{@controller_name.inspect}"
end

#matches?(page_or_node) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_controller.rb', line 18

def matches?(page_or_node)
  page_or_node.has_css?(selector, wait: 0)
end