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.
In Rails 3, add this to your Gemfile:
Alternatively, you can install it as a plugin:
rails plugin install git://github.com/takaltoo/rspec_w3c_matchers.git
RspecW3cMatchers API helpers expect the FlickRaw.api_key to be initialized before they are called:
FlickRaw.api_key = your_flickr_api_key
In RSPEC 2.0 tests you can place the following in your spec_helper.rb file inside the config block
In Cucumber you can place the following in any step definition file that uses the helpers:
Matchers to detect that page is free from errors or warnings:
Matchers to detect that page has specified number of errors or warnings:
You can find a complete list of the matchers by looking at the RspecW3cMatchers::InstanceMethods in RDOCS
A sample RSPEC test that ensures the page has no w3c warnings or errors is given below (assuming body contains the html for the page):
w3c = W3CValidators::MarkupValidator.new response = w3c.validate_text(body) response.should have_no_w3c_errors_in(body) response.should have_no_w3c_warnings_in(body)
A w3c response is can be checked using various matchers. You can generate a w3c response using the w3c_validator gem:
w3c = W3CValidators::MarkupValidator.new response = w3c.validate_text(body)
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:
include RspecW3cMatchers::InstanceMethods Then /^the page should have valid html$/ do w3c = W3CValidators::MarkupValidator.new response = w3c.validate_text(page.body) response.should have_no_w3c_errors_in(page.body) response.should have_no_w3c_warnings_in(page.body) end
Run the specs manually once you have checked out the repository:
rspec spec -f d
If you have any issues with RspecW3cMatchers which you cannot find the solution to in the documentation, please add an issue on GitHub or fork the project and send a pull request.
To get the specs running you should call
bundle and then
Fork the project.
Make your feature addition or bug fix.
Add tests for it. This is important so I do not break it in a future version unintentionally.
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
Send me a pull request.
RspecW3cMatchers is released under the MIT license.
Copyright © 2010 Takaltoo