Class: TurboRspec::Matchers::HaveStimulusAction
- Inherits:
-
Object
- Object
- TurboRspec::Matchers::HaveStimulusAction
- Defined in:
- lib/turbo_rspec/matchers/have_stimulus_action.rb
Overview
RSpec matcher for asserting that a response body contains an element with the given Stimulus action descriptor (+data-action+ contains the descriptor as a space-separated token).
Accepts a full descriptor (+click->hello#greet+) or a shorthand without an event (+hello#greet+), which matches any event prefix.
Instance Method Summary collapse
- #description ⇒ String
- #does_not_match?(response_or_body) ⇒ Boolean
- #failure_message ⇒ String
- #failure_message_when_negated ⇒ String
-
#initialize(action_descriptor) ⇒ HaveStimulusAction
constructor
A new instance of HaveStimulusAction.
- #matches?(response_or_body) ⇒ Boolean
Constructor Details
#initialize(action_descriptor) ⇒ HaveStimulusAction
Returns a new instance of HaveStimulusAction.
20 21 22 |
# File 'lib/turbo_rspec/matchers/have_stimulus_action.rb', line 20 def initialize(action_descriptor) @action_descriptor = action_descriptor.to_s end |
Instance Method Details
#description ⇒ String
48 49 50 |
# File 'lib/turbo_rspec/matchers/have_stimulus_action.rb', line 48 def description "have Stimulus action #{@action_descriptor.inspect}" end |
#does_not_match?(response_or_body) ⇒ Boolean
33 34 35 |
# File 'lib/turbo_rspec/matchers/have_stimulus_action.rb', line 33 def does_not_match?(response_or_body) !matches?(response_or_body) end |
#failure_message ⇒ String
38 39 40 |
# File 'lib/turbo_rspec/matchers/have_stimulus_action.rb', line 38 def "expected response to have Stimulus action #{@action_descriptor.inspect}" end |
#failure_message_when_negated ⇒ String
43 44 45 |
# File 'lib/turbo_rspec/matchers/have_stimulus_action.rb', line 43 def "expected response not to have Stimulus action #{@action_descriptor.inspect}" end |
#matches?(response_or_body) ⇒ Boolean
26 27 28 29 |
# File 'lib/turbo_rspec/matchers/have_stimulus_action.rb', line 26 def matches?(response_or_body) @body = extract_body(response_or_body) Nokogiri::HTML5.fragment(@body).css(selector).any? end |