Class: TurboRspec::Capybara::Matchers::HaveStimulusAction

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

Overview

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

Accepts either a full descriptor (+click->hello#greet+) or a shorthand without an event (+hello#greet+), which matches any event prefix.

Examples:

Full descriptor

expect(page).to have_stimulus_action("click->hello#greet")

Shorthand (any event)

expect(page).to have_stimulus_action("hello#greet")

Instance Method Summary collapse

Constructor Details

#initialize(action_descriptor) ⇒ HaveStimulusAction

Returns a new instance of HaveStimulusAction.



19
20
21
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_action.rb', line 19

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

Instance Method Details

#descriptionObject



39
40
41
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_action.rb', line 39

def description
  "have Stimulus action #{@action_descriptor.inspect}"
end

#does_not_match?(page_or_node) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_action.rb', line 27

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

#failure_messageObject



31
32
33
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_action.rb', line 31

def failure_message
  "expected page to have Stimulus action #{@action_descriptor.inspect}"
end

#failure_message_when_negatedObject



35
36
37
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_action.rb', line 35

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

#matches?(page_or_node) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_action.rb', line 23

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