Class: TurboRspec::Capybara::Matchers::HaveStimulusTarget

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

Overview

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

Examples:

expect(page).to have_stimulus_target("hello", "name")
expect(page).not_to have_stimulus_target("hello", "missing")

Instance Method Summary collapse

Constructor Details

#initialize(controller_name, target_name) ⇒ HaveStimulusTarget

Returns a new instance of HaveStimulusTarget.



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

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

Instance Method Details

#descriptionObject



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

def description
  "have Stimulus target #{@target_name.inspect} for #{@controller_name.inspect}"
end

#does_not_match?(page_or_node) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#failure_messageObject



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

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

#failure_message_when_negatedObject



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

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

#matches?(page_or_node) ⇒ Boolean

Returns:

  • (Boolean)


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

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