Module: Webrat::Matchers

Defined in:
lib/webrat/core/matchers/have_xpath.rb,
lib/webrat/core/matchers/have_content.rb,
lib/webrat/core/matchers/have_selector.rb

Defined Under Namespace

Classes: HasContent, HaveSelector, HaveXpath

Instance Method Summary collapse

Instance Method Details

#assert_contain(content) ⇒ Object

Asserts that the body of the response contain the supplied string or regexp



55
56
57
58
# File 'lib/webrat/core/matchers/have_content.rb', line 55

def assert_contain(content)
  hc = HasContent.new(content)
  assert hc.matches?(current_dom), hc.failure_message
end

#assert_have_no_selector(name, attributes = {}, &block) ⇒ Object

Asserts that the body of the response does not contain the supplied string or regepx



79
80
81
82
# File 'lib/webrat/core/matchers/have_selector.rb', line 79

def assert_have_no_selector(name, attributes = {}, &block)
  matcher = HaveSelector.new(name, attributes, &block)
  assert !matcher.matches?(response_body), matcher.negative_failure_message
end

#assert_have_no_xpath(expected, options = {}, &block) ⇒ Object



118
119
120
121
# File 'lib/webrat/core/matchers/have_xpath.rb', line 118

def assert_have_no_xpath(expected, options = {}, &block)
  hs = HaveXpath.new(expected, options, &block)
  assert !hs.matches?(response_body), hs.negative_failure_message
end

#assert_have_selector(name, attributes = {}, &block) ⇒ Object

Asserts that the body of the response contains the supplied selector



72
73
74
75
# File 'lib/webrat/core/matchers/have_selector.rb', line 72

def assert_have_selector(name, attributes = {}, &block)
  matcher = HaveSelector.new(name, attributes, &block)
  assert matcher.matches?(response_body), matcher.failure_message
end

#assert_have_xpath(expected, options = {}, &block) ⇒ Object



113
114
115
116
# File 'lib/webrat/core/matchers/have_xpath.rb', line 113

def assert_have_xpath(expected, options = {}, &block)
  hs = HaveXpath.new(expected, options, &block)
  assert hs.matches?(response_body), hs.failure_message
end

#assert_not_contain(content) ⇒ Object

Asserts that the body of the response does not contain the supplied string or regepx



62
63
64
65
# File 'lib/webrat/core/matchers/have_content.rb', line 62

def assert_not_contain(content)
  hc = HasContent.new(content)
  assert !hc.matches?(current_dom), hc.negative_failure_message
end

#contain(content) ⇒ Object

Matches the contents of an HTML document with whatever string is supplied



49
50
51
# File 'lib/webrat/core/matchers/have_content.rb', line 49

def contain(content)
  HasContent.new(content)
end

#have_selector(name, attributes = {}, &block) ⇒ Object Also known as: match_selector

Matches HTML content against a CSS 3 selector.

Parameters

expected<String>

The CSS selector to look for.

Returns

HaveSelector

A new have selector matcher.



64
65
66
# File 'lib/webrat/core/matchers/have_selector.rb', line 64

def have_selector(name, attributes = {}, &block)
  HaveSelector.new(name, attributes, &block)
end

#have_xpath(expected, options = {}, &block) ⇒ Object Also known as: match_xpath

Matches HTML content against an XPath query

Parameters

expected<String>

The XPath query to look for.

Returns

HaveXpath

A new have xpath matcher.



108
109
110
# File 'lib/webrat/core/matchers/have_xpath.rb', line 108

def have_xpath(expected, options = {}, &block)
  HaveXpath.new(expected, options, &block)
end