Skip to content

Instantly share code, notes, and snippets.

@qd3v
Last active August 4, 2016 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qd3v/437859585c909da9cd8e to your computer and use it in GitHub Desktop.
Save qd3v/437859585c909da9cd8e to your computer and use it in GitHub Desktop.
# spec_helper.rb
require 'nokogiri'
require 'equivalent-xml/rspec_matchers'
RSpec.configure do |config|
# Should be used with be_equivalent_to provided by 'equivalent-xml' gem
# @see http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Builder
# @see https://github.com/mbklein/equivalent-xml
def xml_document(&block)
Nokogiri::XML::Builder.new(&block).doc
end
end
# OR
# module SpecHelpers
# # Should be used with be_equivalent_to provided by 'equivalent-xml' gem
# # @see http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Builder
# # @see https://github.com/mbklein/equivalent-xml
# def xml_document(&block)
# Nokogiri::XML::Builder.new(&block).doc
# end
# end
# RSpec.configuration.include(SpecHelpers)
# spec
describe "XML", :api do
let(:response_xml) do
<<-XML
<?xml version="1.0" encoding="utf-8"?>
<Response>
<Num>100</Num>
<Body from="100" to="200">Test</Body>
</Response>
XML
end
let(:pattern) do
xml_document do
Response {
Body('Test', from: '100', to: '200')
Num(100)
}
end
end
it "strings" do
expect(response_xml).to be_equivalent_to(pattern)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment