Class: TurboRspec::Capybara::Matchers::HaveTurboFrame
- Inherits:
-
Object
- Object
- TurboRspec::Capybara::Matchers::HaveTurboFrame
- Defined in:
- lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb
Instance Method Summary collapse
- #description ⇒ Object
- #does_not_match?(page_or_node) ⇒ Boolean
-
#eager ⇒ self
Constrains the match to frames with +loading="eager"+.
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(id) ⇒ HaveTurboFrame
constructor
A new instance of HaveTurboFrame.
-
#lazy ⇒ self
Constrains the match to frames with +loading="lazy"+.
- #loaded ⇒ Object
- #matches?(page_or_node) ⇒ Boolean
-
#strict ⇒ self
Constrains the match to frames with the +[strict]+ attribute (Turbo 8).
- #with_content(text) ⇒ Object
-
#with_src(url) ⇒ self
Constrains the match to frames with the given +src+ attribute.
Constructor Details
#initialize(id) ⇒ HaveTurboFrame
Returns a new instance of HaveTurboFrame.
7 8 9 10 11 12 13 14 15 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 7 def initialize(id) @id = id.to_s @content = nil @loaded = false @src = nil @lazy = false @eager = false @strict = false end |
Instance Method Details
#description ⇒ Object
94 95 96 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 94 def description "have turbo-frame##{@id}#{constraint_description}" end |
#does_not_match?(page_or_node) ⇒ Boolean
68 69 70 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 68 def does_not_match?(page_or_node) !matches?(page_or_node) end |
#eager ⇒ self
Constrains the match to frames with +loading="eager"+.
44 45 46 47 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 44 def eager @eager = true self end |
#failure_message ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 72 def if @node.nil? "expected page to have turbo-frame##{@id}#{constraint_description} but it was not found" elsif @loaded && !@node[:complete] "expected turbo-frame##{@id} to be loaded (missing [complete] attribute)" elsif @lazy && @node[:loading] != "lazy" "expected turbo-frame##{@id} to be lazy (missing loading=\"lazy\" attribute)" elsif @eager && @node[:loading] != "eager" "expected turbo-frame##{@id} to be eager (missing loading=\"eager\" attribute)" elsif @strict && @node[:strict].nil? "expected turbo-frame##{@id} to be strict (missing [strict] attribute)" elsif @src && @node[:src] != @src "expected turbo-frame##{@id} to have src #{@src.inspect}, got #{@node[:src].inspect}" else "expected turbo-frame##{@id} to have content #{@content.inspect}" end end |
#failure_message_when_negated ⇒ Object
90 91 92 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 90 def "expected page not to have turbo-frame##{@id}#{constraint_description}" end |
#lazy ⇒ self
Constrains the match to frames with +loading="lazy"+.
37 38 39 40 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 37 def lazy @lazy = true self end |
#loaded ⇒ Object
22 23 24 25 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 22 def loaded @loaded = true self end |
#matches?(page_or_node) ⇒ Boolean
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 56 def matches?(page_or_node) @node = find_frame(page_or_node) return false unless @node return false if @loaded && !@node[:complete] return false if @lazy && @node[:loading] != "lazy" return false if @eager && @node[:loading] != "eager" return false if @strict && @node[:strict].nil? return false if @src && @node[:src] != @src return false if @content && !@node.has_content?(@content, wait: 0) true end |
#strict ⇒ self
Constrains the match to frames with the +[strict]+ attribute (Turbo 8).
51 52 53 54 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 51 def strict @strict = true self end |
#with_content(text) ⇒ Object
17 18 19 20 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 17 def with_content(text) @content = text.to_s self end |
#with_src(url) ⇒ self
Constrains the match to frames with the given +src+ attribute.
30 31 32 33 |
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 30 def with_src(url) @src = url.to_s self end |