Class: TurboRspec::Capybara::Matchers::HaveTurboFrame

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ HaveTurboFrame

Returns a new instance of HaveTurboFrame.



7
8
9
10
11
12
13
# 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
end

Instance Method Details

#descriptionObject



72
73
74
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 72

def description
  "have turbo-frame##{@id}#{constraint_description}"
end

#does_not_match?(page_or_node) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 50

def does_not_match?(page_or_node)
  !matches?(page_or_node)
end

#failure_messageObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 54

def failure_message
  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 @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_negatedObject



68
69
70
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 68

def failure_message_when_negated
  "expected page not to have turbo-frame##{@id}#{constraint_description}"
end

#lazyself

Constrains the match to frames with +loading="lazy"+.

Returns:

  • (self)


35
36
37
38
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 35

def lazy
  @lazy = true
  self
end

#loadedObject



20
21
22
23
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 20

def loaded
  @loaded = true
  self
end

#matches?(page_or_node) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 40

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 @src && @node[:src] != @src
  return false if @content && !@node.has_content?(@content, wait: 0)
  true
end

#with_content(text) ⇒ Object



15
16
17
18
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 15

def with_content(text)
  @content = text.to_s
  self
end

#with_src(url) ⇒ self

Constrains the match to frames with the given +src+ attribute.

Parameters:

  • url (String)

Returns:

  • (self)


28
29
30
31
# File 'lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb', line 28

def with_src(url)
  @src = url.to_s
  self
end