Last active
August 4, 2016 13:49
-
-
Save qd3v/437859585c909da9cd8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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