Sha256: cae61f2d5254ab3541fa7e34fe63c1a3453e1aa06c6067acb564cd04e9f78727

Contents?: true

Size: 1.21 KB

Versions: 9

Compression:

Stored size: 1.21 KB

Contents

# encoding: UTF-8

require 'tmpdir'
require 'vines'
require 'ext/nokogiri'
require 'minitest/autorun'
require 'rails/all'

class MiniTest::Spec

  # Build an <iq> xml node with the given attributes. This is useful as a
  # quick way to build a node to use as expected stanza output from a
  # Stream#write call.
  #
  # options - The Hash of xml attributes to include on the iq element. Attribute
  #           values of nil or empty? are excluded from the generated element.
  #           :body - The String xml content to include in the iq element.
  #
  # Examples
  #
  #   iq(from: from, id: 42, to: to, type: 'result', body: card)
  #
  # Returns a Nokogiri::XML::Node.
  def iq(options)
    body = options.delete(:body)
    options.delete_if {|k, v| v.nil? || v.to_s.empty? }
    attrs = options.map {|k, v| "#{k}=\"#{v}\"" }.join(' ')
    node("<iq #{attrs}>#{body}</iq>")
  end

  # Parse xml into a nokogiri node. Strip excessive whitespace from the xml
  # content before parsing because it affects comparisons in MiniTest::Mock
  # expectations.
  #
  # xml - The String of xml content to parse.
  #
  # Returns a Nokogiri::XML::Node.
  def node(xml)
    xml = xml.strip.gsub(/\n|\s{2,}/, '')
    Nokogiri::XML(xml).root
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
diaspora-vines-0.2.0.develop.2 test/test_helper.rb
diaspora-vines-0.2.0.develop.1 test/test_helper.rb
diaspora-vines-0.1.28 test/test_helper.rb
diaspora-vines-0.1.27 test/test_helper.rb
diaspora-vines-0.1.26 test/test_helper.rb
diaspora-vines-0.1.25 test/test_helper.rb
diaspora-vines-0.1.24 test/test_helper.rb
diaspora-vines-0.1.22 test/test_helper.rb
diaspora-vines-0.1.21 test/test_helper.rb