Class: TurboRspec::Matchers::HaveTurboFrame
- Inherits:
-
Object
- Object
- TurboRspec::Matchers::HaveTurboFrame
- Defined in:
- lib/turbo_rspec/matchers/have_turbo_frame.rb
Overview
RSpec matcher for asserting that a response body contains a
+
Instance Method Summary collapse
- #description ⇒ Object
- #does_not_match?(response_or_body) ⇒ Boolean
- #failure_message ⇒ String
- #failure_message_when_negated ⇒ String
-
#initialize ⇒ HaveTurboFrame
constructor
A new instance of HaveTurboFrame.
- #matches?(response_or_body) ⇒ Boolean
-
#rendering(partial) ⇒ self
Constrains the match to frames whose HTML includes the given partial path.
-
#with_attributes(attrs) ⇒ self
Constrains the match to frames that have all of the given HTML attributes.
-
#with_content(text) ⇒ self
Constrains the match to frames whose content includes the given text.
-
#with_id(id) ⇒ self
Constrains the match to frames with the given id attribute.
Constructor Details
#initialize ⇒ HaveTurboFrame
Returns a new instance of HaveTurboFrame.
20 21 22 23 24 25 |
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 20 def initialize @id = nil @content = nil @partial = nil @attributes = {} end |
Instance Method Details
#description ⇒ Object
83 84 85 |
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 83 def description "have turbo frame#{constraint_description}" end |
#does_not_match?(response_or_body) ⇒ Boolean
69 70 71 |
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 69 def does_not_match?(response_or_body) !matches?(response_or_body) end |
#failure_message ⇒ String
74 75 76 |
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 74 def "expected response to contain a turbo frame#{constraint_description}\n#{}" end |
#failure_message_when_negated ⇒ String
79 80 81 |
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 79 def "expected response not to contain a turbo frame#{constraint_description}" end |
#matches?(response_or_body) ⇒ Boolean
61 62 63 64 65 |
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 61 def matches?(response_or_body) @body = extract_body(response_or_body) @frames = parse_frames(@body) @frames.any? { |frame| frame_matches?(frame) } end |
#rendering(partial) ⇒ self
Constrains the match to frames whose HTML includes the given partial path.
46 47 48 49 |
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 46 def rendering(partial) @partial = partial.to_s self end |
#with_attributes(attrs) ⇒ self
Constrains the match to frames that have all of the given HTML attributes.
54 55 56 57 |
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 54 def with_attributes(attrs) @attributes = attrs.transform_keys(&:to_s).transform_values(&:to_s) self end |
#with_content(text) ⇒ self
Constrains the match to frames whose content includes the given text.
38 39 40 41 |
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 38 def with_content(text) @content = text.to_s self end |
#with_id(id) ⇒ self
Constrains the match to frames with the given id attribute.
30 31 32 33 |
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 30 def with_id(id) @id = id.to_s self end |