Class: Spec::Rails::Matchers::ImageMatcher
- Inherits:
-
Object
- Object
- Spec::Rails::Matchers::ImageMatcher
- Defined in:
- lib/matchers/image_matcher.rb
Instance Method Summary collapse
- #extract_html_content(html) ⇒ Object
- #failure_message ⇒ Object
-
#initialize(expected_path) ⇒ ImageMatcher
constructor
A new instance of ImageMatcher.
- #matches?(response) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(expected_path) ⇒ ImageMatcher
Returns a new instance of ImageMatcher.
5 6 7 |
# File 'lib/matchers/image_matcher.rb', line 5 def initialize expected_path @expected = expected_path end |
Instance Method Details
#extract_html_content(html) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/matchers/image_matcher.rb', line 22 def extract_html_content html doc = Hpricot.XML(html) elements = doc.search("img[@src*=\"#{@expected}\"]") # elements.each {|e| puts e.inspect} # elements.first.to_html elements.map{|n| n.to_html}.first end |
#failure_message ⇒ Object
14 15 16 |
# File 'lib/matchers/image_matcher.rb', line 14 def "\nWrong image path.\nexpected: #{@expected.inspect}\n found: #{@actual.inspect}\n\n" end |
#matches?(response) ⇒ Boolean
9 10 11 12 |
# File 'lib/matchers/image_matcher.rb', line 9 def matches? response @actual = extract_html_content response.body @actual =~ /#{@expected}/ end |
#negative_failure_message ⇒ Object
18 19 20 |
# File 'lib/matchers/image_matcher.rb', line 18 def "\nShould not have matched image with path: '#{@expected}'\n\n" end |