Module: Hermes::Assertions

Included in:
IntegrationCase
Defined in:
lib/hermes/assertions.rb

Overview

A few assertions built on top of Capybara.

Constant Summary collapse

METHODS =
{
  'xpath' => 'no_xpath',
  'css' => 'no_css',
  'link' => 'no_link',
  'select' => 'no_select',
  'field' => 'no_field',
  'button' => 'no_button',
  'checked_field' => 'unchecked_field',
  'selector' => 'no_selector',
  'table' => 'no_table'
}.freeze

Instance Method Summary collapse

Instance Method Details

#assert_content(content) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/hermes/assertions.rb', line 33

def assert_content(content)
  if has_content?(content)
    assert_block("assert_content") { true }
  else
    assert_block("#{body_inner_text}\nExpected to have #{content}"){ false }
  end
end

#assert_current_path(expected) ⇒ Object



17
18
19
# File 'lib/hermes/assertions.rb', line 17

def assert_current_path(expected)
  assert_equal expected, current_path
end

#assert_difference_on_click_button(button, *args) ⇒ Object



21
22
23
24
25
# File 'lib/hermes/assertions.rb', line 21

def assert_difference_on_click_button(button, *args)
  assert_difference(*args) do
    click_button button
  end
end


27
28
29
30
31
# File 'lib/hermes/assertions.rb', line 27

def assert_difference_on_click_link(link, *args)
  assert_difference(*args) do
    click_link link
  end
end


76
77
78
79
80
81
# File 'lib/hermes/assertions.rb', line 76

def assert_link_to(url, options={})
  msg = "#{page.body}\nExpected to have link to #{url}"
  assert_block(msg) do
    has_css? "a[href*='%s']" % url, options
  end
end

#assert_mail_deliveries(many = 1) ⇒ Object



72
73
74
# File 'lib/hermes/assertions.rb', line 72

def assert_mail_deliveries(many=1)
  assert_difference("ActionMailer::Base.deliveries.size", many){ yield }
end

#assert_no_content(content) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/hermes/assertions.rb', line 41

def assert_no_content(content)
  boolean = has_content?(content)
  if boolean
    assert_block("#{body_inner_text}\nExpected to have no content #{content}"){ false }
  else
    assert_block("assert_no_content") { true }
  end
end