Class: TurboRspec::Matchers::HaveStimulusController
- Inherits:
-
Object
- Object
- TurboRspec::Matchers::HaveStimulusController
- Defined in:
- lib/turbo_rspec/matchers/have_stimulus_controller.rb
Overview
RSpec matcher for asserting that a response body contains an element with the given Stimulus controller (+data-controller+ contains the name as a space-separated token).
Instance Method Summary collapse
- #description ⇒ String
- #does_not_match?(response_or_body) ⇒ Boolean
- #failure_message ⇒ String
- #failure_message_when_negated ⇒ String
-
#initialize(controller_name) ⇒ HaveStimulusController
constructor
A new instance of HaveStimulusController.
- #matches?(response_or_body) ⇒ Boolean
Constructor Details
#initialize(controller_name) ⇒ HaveStimulusController
Returns a new instance of HaveStimulusController.
15 16 17 |
# File 'lib/turbo_rspec/matchers/have_stimulus_controller.rb', line 15 def initialize(controller_name) @controller_name = controller_name.to_s end |
Instance Method Details
#description ⇒ String
43 44 45 |
# File 'lib/turbo_rspec/matchers/have_stimulus_controller.rb', line 43 def description "have Stimulus controller #{@controller_name.inspect}" end |
#does_not_match?(response_or_body) ⇒ Boolean
28 29 30 |
# File 'lib/turbo_rspec/matchers/have_stimulus_controller.rb', line 28 def does_not_match?(response_or_body) !matches?(response_or_body) end |
#failure_message ⇒ String
33 34 35 |
# File 'lib/turbo_rspec/matchers/have_stimulus_controller.rb', line 33 def "expected response to have Stimulus controller #{@controller_name.inspect}" end |
#failure_message_when_negated ⇒ String
38 39 40 |
# File 'lib/turbo_rspec/matchers/have_stimulus_controller.rb', line 38 def "expected response not to have Stimulus controller #{@controller_name.inspect}" end |
#matches?(response_or_body) ⇒ Boolean
21 22 23 24 |
# File 'lib/turbo_rspec/matchers/have_stimulus_controller.rb', line 21 def matches?(response_or_body) @body = extract_body(response_or_body) Nokogiri::HTML5.fragment(@body).css("[data-controller~='#{@controller_name}']").any? end |