Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A collection of custom RSpec Matchers for testing XML
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
spec_examples
test_xml
.gitignore
README.markdown
Rakefile

README.markdown

rspec_xml_matchers

Overview

A collection of custom RSpec Matchers for testing XML. Currently it supports XPath and Schema Validation matchers, and will be expanded to support XML equivalence testing. Look in the "spec_examples" directory for more examples, but the following is what you can expect to find.

XPath Matchers (see "spec_examples/rspec_xml_matchers_xpath_spec.rb")

xml.should contain_xpath("/vehicles/vehicle[1]")
xml.should contain_xpath("/vehicles/vehicle[1]/make").with_text_value("BMW")
xml.should contain_xpath("/vehicles/vehicle[1]/model").with_text_value("335is")

XPath Matchers with Namespace Prefixes (see "spec_examples/rspec_xml_matchers_xpath_nsprefix_spec.rb")

namespaces = { 'x' => 'urn:test:vehicles' }
xml.should contain_xpath("/x:vehicles/x:vehicle[1]/x:make", { 'x' => 'urn:test:vehicles' })
xml.should contain_xpath("/x:vehicles/x:vehicle[1]/x:make", namespaces).with_text_value("BMW")
xml.should contain_xpath("/x:vehicles/x:vehicle[1]/x:model", namespaces).with_text_value("335is")

Schema Validation Matchers (see "spec_examples/rspec_xml_matchers_schema_spec.rb")

xml.should validate_against_schema(File.new("vehicles.xsd"))
Something went wrong with that request. Please try again.