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



60
61
62
63
# File 'lib/webrat/core/matchers/have_content.rb', line 60

def assert_contain(content)
  hc = HasContent.new(content)
  assert hc.matches?(response_body), 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



68
69
70
71
# File 'lib/webrat/core/matchers/have_selector.rb', line 68

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



141
142
143
144
# File 'lib/webrat/core/matchers/have_xpath.rb', line 141

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



61
62
63
64
# File 'lib/webrat/core/matchers/have_selector.rb', line 61

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



136
137
138
139
# File 'lib/webrat/core/matchers/have_xpath.rb', line 136

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



67
68
69
70
# File 'lib/webrat/core/matchers/have_content.rb', line 67

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

#contain(content) ⇒ Object

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



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

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.



53
54
55
# File 'lib/webrat/core/matchers/have_selector.rb', line 53

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.



131
132
133
# File 'lib/webrat/core/matchers/have_xpath.rb', line 131

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