Class: Spec::Rails::Matchers::TdLinkMatcher
- Inherits:
-
Object
- Object
- Spec::Rails::Matchers::TdLinkMatcher
- Defined in:
- lib/matchers/td_link_matcher.rb
Instance Method Summary collapse
- #extract_html_content(html) ⇒ Object
- #failure_message ⇒ Object
-
#initialize(target_id, expected_text, expected_link) ⇒ TdLinkMatcher
constructor
A new instance of TdLinkMatcher.
- #matches?(response) ⇒ Boolean
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_message ⇒ Object
17 18 19 |
# File 'lib/matchers/td_link_matcher.rb', line 17 def "\nWrong #{@element_name} contents.\nexpected: #{@expected_text.inspect}\n found: #{@actual_text.inspect}\n\n" end |
#matches?(response) ⇒ 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 |