# 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 100 Test 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