Skip to content

Instantly share code, notes, and snippets.

@qd3v
Last active August 4, 2016 13:49
Show Gist options
  • Save qd3v/437859585c909da9cd8e to your computer and use it in GitHub Desktop.
Save qd3v/437859585c909da9cd8e to your computer and use it in GitHub Desktop.

Revisions

  1. Ivan Byurganovskiy revised this gist Aug 4, 2016. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions rspec_xml_matching.rb
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,19 @@ def xml_document(&block)
    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
  2. Ivan Byurganovskiy revised this gist Jul 31, 2015. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions rspec_xml_matching.rb
    Original file line number Diff line number Diff line change
    @@ -13,12 +13,12 @@ def xml_document(&block)

    # spec

    describe "XML" do
    # <?xml?> can be skipped safely, it will still match
    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
    @@ -28,11 +28,12 @@ def xml_document(&block)
    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
    end
  3. Ivan Byurganovskiy revised this gist Jul 31, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions rspec_xml_matching.rb
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@
    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
    @@ -13,6 +14,7 @@ def xml_document(&block)
    # spec

    describe "XML" do
    # <?xml?> can be skipped safely, it will still match
    let(:response_xml) do
    <<-XML
    <?xml version="1.0" encoding="utf-8"?>
  4. Ivan Byurganovskiy created this gist Jul 31, 2015.
    36 changes: 36 additions & 0 deletions rspec_xml_matching.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    # 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
    def xml_document(&block)
    Nokogiri::XML::Builder.new(&block).doc
    end
    end

    # spec

    describe "XML" do
    let(:response_xml) do
    <<-XML
    <?xml version="1.0" encoding="utf-8"?>
    <Response>
    <Body from="100" to="200">Test</Body>
    </Response>
    XML
    end

    let(:pattern) do
    xml_document do
    Response {
    Body('Test', from: '100', to: '200')
    }
    end
    end

    it "strings" do
    expect(response_xml).to be_equivalent_to(pattern)
    end
    end