Module: Locator::Matcher

Defined in:
lib/locator/matcher.rb,
lib/locator/matcher/have_tag.rb,
lib/locator/matcher/have_css_class.rb

Defined Under Namespace

Classes: HaveCssClass, HaveTag

Instance Method Summary collapse

Instance Method Details

#assert_contains(*args) ⇒ Object

Asserts that the response body contains the given string or regexp



28
29
30
31
# File 'lib/locator/matcher.rb', line 28

def assert_contains(*args)
  matcher = contain(*args)
  assert matcher.matches?(response.body), matcher.failure_message
end

#assert_css_class(css_classes, css_class) ⇒ Object



73
74
75
76
# File 'lib/locator/matcher.rb', line 73

def assert_css_class(css_classes, css_class)
  matcher = HaveCssClass.new(css_class)
  assert matcher.matches?(css_classes.body), matcher.failure_message
end

#assert_does_not_contain(*args) ⇒ Object

Asserts that the response body does not contain the given string or regexp



34
35
36
37
# File 'lib/locator/matcher.rb', line 34

def assert_does_not_contain(*args)
  matcher = contain(*args)
  assert !matcher.matches?(response.body), matcher.negative_failure_message
end

#assert_has_css(html, *args, &block) ⇒ Object

Asserts that the response body matches the given CSS selector



62
63
64
65
# File 'lib/locator/matcher.rb', line 62

def assert_has_css(html, *args, &block)
  matcher = have_css(*args, &block)
  assert matcher.matches?(response.body), matcher.failure_message
end

#assert_has_tag(html, *args, &block) ⇒ Object



39
40
41
42
# File 'lib/locator/matcher.rb', line 39

def assert_has_tag(html, *args, &block)
  matcher = have_tag(*args, &block)
  assert matcher.matches?(response.body), matcher.failure_message
end

#assert_has_xpath(html, *args, &block) ⇒ Object

Asserts that the response body matches the given XPath



50
51
52
53
# File 'lib/locator/matcher.rb', line 50

def assert_has_xpath(html, *args, &block)
  matcher = have_xpath(*args, &block)
  assert matcher.matches?(response.body), matcher.failure_message
end

#assert_no_css(html, *args, &block) ⇒ Object

Asserts that the response body does not match the given CSS selector



68
69
70
71
# File 'lib/locator/matcher.rb', line 68

def assert_no_css(html, *args, &block)
  matcher = have_css(*args, &block)
  assert !matcher.matches?(response.body), matcher.negative_failure_message
end

#assert_no_css_class(css_classes, css_class) ⇒ Object



78
79
80
81
# File 'lib/locator/matcher.rb', line 78

def assert_no_css_class(css_classes, css_class)
  matcher = HaveCssClass.new(css_class)
  assert matcher.matches?(css_classes.body), matcher.negative_failure_message
end

#assert_no_tag(html, *args, &block) ⇒ Object



44
45
46
47
# File 'lib/locator/matcher.rb', line 44

def assert_no_tag(html, *args, &block)
  matcher = have_tag(*args, &block)
  assert !matcher.matches?(response.body), matcher.negative_failure_message
end

#assert_no_xpath(html, *args, &block) ⇒ Object

Asserts that the response body does not match the given XPath



56
57
58
59
# File 'lib/locator/matcher.rb', line 56

def assert_no_xpath(html, *args, &block)
  matcher = have_xpath(*args, &block)
  assert !matcher.matches?(response.body), matcher.negative_failure_message
end

#contain(*args) ⇒ Object

Matches an HTML document with whatever string is given



7
8
9
# File 'lib/locator/matcher.rb', line 7

def contain(*args)
  HaveTag.new(*args)
end

#have_css(css, options = {}, &block) ⇒ Object



19
20
21
# File 'lib/locator/matcher.rb', line 19

def have_css(css, options = {}, &block)
  HaveTag.new(options.delete(:content), options.merge(:css => css), &block)
end

#have_css_class(css_class) ⇒ Object



23
24
25
# File 'lib/locator/matcher.rb', line 23

def have_css_class(css_class)
  HaveCssClass.new(css_class)
end

#have_tag(*args, &block) ⇒ Object



11
12
13
# File 'lib/locator/matcher.rb', line 11

def have_tag(*args, &block)
  HaveTag.new(*args, &block)
end

#have_xpath(xpath, options = {}, &block) ⇒ Object



15
16
17
# File 'lib/locator/matcher.rb', line 15

def have_xpath(xpath, options = {}, &block)
  HaveTag.new(options.delete(:content), options.merge(:xpath => xpath), &block)
end