Class: PageValidations::HaveValidHTML

Inherits:
Object
  • Object
show all
Defined in:
lib/html_validation/have_valid_html.rb

Constant Summary collapse

@@html_in_failures =

This is the matching method called by RSpec The response is passed in as an argument when you do this: page.should have_valid_html

false

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.show_html_in_failures=(val) ⇒ Object



13
14
15
# File 'lib/html_validation/have_valid_html.rb', line 13

def self.show_html_in_failures=(val)
  @@html_in_failures = val
end

Instance Method Details

#descriptionObject



23
24
25
# File 'lib/html_validation/have_valid_html.rb', line 23

def description
  "Have valid html"
end

#failure_message_for_shouldObject



27
28
29
# File 'lib/html_validation/have_valid_html.rb', line 27

def failure_message_for_should
  "#{@v.resource} Invalid html (fix or run 'html_validation review' to add exceptions)\n#{@v.resource} exceptions:\n #{@v.exceptions}\n\n #{@v.html if @@html_in_failures}"
end

#failure_message_for_should_notObject



31
32
33
# File 'lib/html_validation/have_valid_html.rb', line 31

def failure_message_for_should_not
  "#{@v.resource} Expected valid? to fail but didn't. Did you accidentally accept these validation errors?  \n#{@v.resource} exceptions:\n #{@v.exceptions}\n\n #{@v.html if @@html_in_failures}"
end

#matches?(page) ⇒ Boolean

Returns:



17
18
19
20
21
# File 'lib/html_validation/have_valid_html.rb', line 17

def matches?(page)
  h  = HTMLValidation.new
  @v = h.validation(page.body, page.current_url)
  @v.valid?
end