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



11
12
13
# File 'lib/html_validation/have_valid_html.rb', line 11

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

Instance Method Details

#descriptionObject



21
22
23
# File 'lib/html_validation/have_valid_html.rb', line 21

def description
  "have valid HTML"
end

#failure_message_for_shouldObject Also known as: failure_message



25
26
27
# File 'lib/html_validation/have_valid_html.rb', line 25

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 Also known as: failure_message_when_negated



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

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:

  • (Boolean)


15
16
17
18
19
# File 'lib/html_validation/have_valid_html.rb', line 15

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