Class: StimulusSpec::Matchers::HaveStimulusTarget
- Inherits:
-
Object
- Object
- StimulusSpec::Matchers::HaveStimulusTarget
- Defined in:
- lib/stimulus_spec/matchers/have_stimulus_target.rb
Instance Method Summary collapse
- #description ⇒ Object
- #does_not_match?(subject) ⇒ Boolean
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(controller, target) ⇒ HaveStimulusTarget
constructor
A new instance of HaveStimulusTarget.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(controller, target) ⇒ HaveStimulusTarget
Returns a new instance of HaveStimulusTarget.
6 7 8 9 |
# File 'lib/stimulus_spec/matchers/have_stimulus_target.rb', line 6 def initialize(controller, target) @controller = controller.to_s @target = target.to_s end |
Instance Method Details
#description ⇒ Object
28 29 30 |
# File 'lib/stimulus_spec/matchers/have_stimulus_target.rb', line 28 def description "have Stimulus target \"#{@target}\" for controller \"#{@controller}\"" end |
#does_not_match?(subject) ⇒ Boolean
16 17 18 |
# File 'lib/stimulus_spec/matchers/have_stimulus_target.rb', line 16 def does_not_match?(subject) !matches?(subject) end |
#failure_message ⇒ Object
20 21 22 |
# File 'lib/stimulus_spec/matchers/have_stimulus_target.rb', line 20 def "expected to find an element with data-#{@controller}-target=\"#{@target}\" but found none in:\n#{@body}" end |
#failure_message_when_negated ⇒ Object
24 25 26 |
# File 'lib/stimulus_spec/matchers/have_stimulus_target.rb', line 24 def "expected not to find an element with data-#{@controller}-target=\"#{@target}\" but found one" end |
#matches?(subject) ⇒ Boolean
11 12 13 14 |
# File 'lib/stimulus_spec/matchers/have_stimulus_target.rb', line 11 def matches?(subject) @body = extract_body(subject) !document.at_css("[data-#{@controller}-target~='#{@target}']").nil? end |