https://github.com/alovak/test_xml
Small library to test your xml with Test::Unit or RSpec
https://github.com/alovak/test_xml
Last synced: about 2 months ago
JSON representation
Small library to test your xml with Test::Unit or RSpec
- Host: GitHub
- URL: https://github.com/alovak/test_xml
- Owner: alovak
- License: other
- Created: 2010-01-01T20:06:04.000Z (about 16 years ago)
- Default Branch: master
- Last Pushed: 2016-11-25T21:43:49.000Z (about 9 years ago)
- Last Synced: 2025-11-03T22:15:04.759Z (2 months ago)
- Language: Ruby
- Homepage:
- Size: 74.2 KB
- Stars: 30
- Watchers: 3
- Forks: 8
- Open Issues: 6
-
Metadata Files:
- Readme: README.rdoc
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ruby - TestXml - TestXml is a small extension for testing XML/HTML. (Testing)
- fucking-awesome-ruby - TestXml - TestXml is a small extension for testing XML/HTML. (Testing)
- awesome-ruby - TestXml - TestXml is a small extension for testing XML/HTML. (Testing)
README
= TestXml
== DESCRIPTION
TestXml is a small extension for testing XML/HTML. Extending RSpec and TestUnit it makes asserting and comparing XML snippets easy, and is especially helpful for testing RESTful web services and their XML representations.
== FEATURES
* Runs with RSpec 2 or 3, Test::Unit, MiniTest and Cucumber
* Ruby >= 1.8
* Test XML structure and content
== INSTALL
gem install test_xml
== EXAMPLES
=== Test::Unit and MiniTest
def test_item_representation
assert_xml_equal "1", @item.to_xml
end
=== RSpec
it "should contain the id" do
@item.to_xml.should equal_xml(<<-XML)
1
XML
end
=== Cucumber
Scenario:
When I post some data
Then the response should match the following xml
"""
success
"""
== USAGE:
=== RSpec
In your spec_helper.rb
require 'test_xml/spec'
And in the actual spec, use these matchers:
* equal_xml
* contain_xml
* equal_xml_structure
* contain_xml_structure
=== Test::Unit
In the test_helper.rb
require 'test_xml/test_unit'
In your test file, use these matchers:
* assert_xml_equal
* assert_xml_contain
* assert_xml_structure_equal
* assert_xml_structure_contain
Negative assertions are available as assert_not_*.
=== MiniTest
In the test_helper.rb
require 'test_xml/mini_test'
Check the Test::Unit section for available assertions.
=== Cucumber
In the features/env.rb
require 'test_xml'
require 'test_xml/spec'
World(TestXml::Spec)
In your steps file e.g. features/step_definitions/xml_steps.rb add this step:
Then /^the response should match the following xml$/ do |xml|
response.body.should equal_xml(xml)
end
== ASSERTIONS
=== XML is Equal
Elements, attributes and text nodes are all the same
=== XML Contains
The XML contains the given structure. Checks ancestral relationships, elements, attributes and text nodes starting from and including the root node.
For example, given this XML:
This will fail:
Cee
as +b+ is not the root node. The check must be written as:
=== XML Structure is Equal
Like XML is equal, but ignores attributes and text nodes
=== XML Structure Contains
Like XML contains, but ignores attributes and text nodes
== REQUIREMENTS
* nokogiri
== Many Thanks
{Nick Sutterer}[http://github.com/apotonick] thank you for bringing RSpec 2, Ruby 1.9.2 and MiniTest! You revived the gem! :)
== LICENSE
Copyright © 2010-2011, Pavel Gabriel
Released under the MIT License.