Class: Spec::Rails::Matchers::TdLinkMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/matchers/td_link_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(target_id, expected_text, expected_link) ⇒ TdLinkMatcher

Returns a new instance of TdLinkMatcher.



6
7
8
9
10
# File 'lib/matchers/td_link_matcher.rb', line 6

def initialize target_id, expected_text, expected_link
  @xpath = "td##{target_id}"
  @expected_link = expected_link
  @expected_text = expected_text
end

Instance Method Details

#extract_html_content(html) ⇒ Object



21
22
23
24
25
# File 'lib/matchers/td_link_matcher.rb', line 21

def extract_html_content html
  doc = Hpricot.XML(html)
  elements = doc.search(@xpath)
  elements.map{|n| n.inner_text.strip}.first
end

#failure_messageObject



17
18
19
# File 'lib/matchers/td_link_matcher.rb', line 17

def failure_message
  "\nWrong #{@element_name} contents.\nexpected: #{@expected_text.inspect}\n   found: #{@actual_text.inspect}\n\n"
end

#matches?(response) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/matchers/td_link_matcher.rb', line 12

def matches? response
  @actual_text = extract_html_content response.body
  @actual_text == @expected_text
end