Class: TurboRspec::Capybara::Matchers::HaveStimulusTarget
- Inherits:
-
Object
- Object
- TurboRspec::Capybara::Matchers::HaveStimulusTarget
- 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.
Instance Method Summary collapse
- #description ⇒ Object
- #does_not_match?(page_or_node) ⇒ Boolean
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(controller_name, target_name) ⇒ HaveStimulusTarget
constructor
A new instance of HaveStimulusTarget.
- #matches?(page_or_node) ⇒ Boolean
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
#description ⇒ Object
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
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_message ⇒ Object
27 28 29 |
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_target.rb', line 27 def "expected page to have Stimulus target #{@target_name.inspect} for controller #{@controller_name.inspect}" end |
#failure_message_when_negated ⇒ Object
31 32 33 |
# File 'lib/turbo_rspec/capybara/matchers/have_stimulus_target.rb', line 31 def "expected page not to have Stimulus target #{@target_name.inspect} for controller #{@controller_name.inspect}" end |
#matches?(page_or_node) ⇒ 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 |