RspecW3cMatchers

RspecW3cMatchers provides custom matchers for detecting validation errors
reported by w3c validator service.
The w3c_validator
gem by alexdunae. The
matchers return detailed information regarding errors or warnings that are
returned by the w3c validator.

Installation

In Rails 3, add this to your Gemfile:

gem"flickrmocks"

Alternatively, you can install it as a plugin:

rails plugin install git://github.com/takaltoo/rspec_w3c_matchers.git

Getting Started

RspecW3cMatchers API helpers expect the FlickRaw.api_key to be initialized
before they are called:

FlickRaw.api_key=your_flickr_api_key

Including the matchers in Rspec or Cucumber

In RSPEC 2.0 tests you can place the following in your
spec_helper.rb file inside the config block

Generating a response object from W3C validator

Once you have the response you can compare it against a matcher. NOTE: the
variable body contains the html for the page. If you are using Capybara and Cucumber you can
simply access the text by passing in 'page.body'.

A sample step file for cucumber (that is used with capybara) is given
below:

includeRspecW3cMatchers::InstanceMethodsThen/^the page should have valid html$/dow3c=W3CValidators::MarkupValidator.newresponse=w3c.validate_text(page.body)response.shouldhave_no_w3c_errors_in(page.body)response.shouldhave_no_w3c_warnings_in(page.body)end