Class: Booth::Testing::Support::AssertPartial

Inherits:
Object
  • Object
show all
Includes:
Logging, Calls, Capybara::DSL
Defined in:
lib/booth/testing/support/assert_partial.rb

Instance Method Summary collapse

Instance Method Details

#actual_tagObject



36
37
38
39
# File 'lib/booth/testing/support/assert_partial.rb', line 36

def actual_tag
  page.html.scan(%r{<template>[^/]+/[^/]+/[^/]+</template>}).uniq.first.presence ||
    page.text
end

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/booth/testing/support/assert_partial.rb', line 17

def call
  ::Capybara::Lockstep.synchronize
  log { "Looking for view `#{partial}`" }

  assert_selector 'template', visible: false

  content = page.html.match(%r{<template>([^<]+)</template>})[1].strip

  raise "Expected view '#{partial}' but got '#{content}'" unless content == partial

  log { "The expected view `#{partial}` was rendered." }
  self.class.asserted_partials << partial
  nil
end

#expected_tagObject



32
33
34
# File 'lib/booth/testing/support/assert_partial.rb', line 32

def expected_tag
  "<template>#{partial}</template>"
end

#partialObject



41
42
43
# File 'lib/booth/testing/support/assert_partial.rb', line 41

def partial
  "#{namespace}/#{controller}/#{step}"
end

#test_file_and_line_numberObject



45
46
47
48
49
50
51
52
# File 'lib/booth/testing/support/assert_partial.rb', line 45

def test_file_and_line_number
  # Called from e.g. `::Booth::Testing::Userland::LoginRemotely`.
  candidate = caller[3].split(':in ').first
  return candidate unless candidate.include?('calls')

  # Called from e.g. `::Booth::Testing::Support::RegisterNewPasskey`.
  caller[2].split(':in ').first
end