module MiniTest::Assertions

Public Instance Methods

assert_serialize_to(exp, act, opts) click to toggle source
# File tests/cimi/spec/spec_helper.rb, line 114
def assert_serialize_to(exp, act, opts)
  raise "missing format; use :fmt => [:xml || :json]" if opts[:fmt].nil?
  exp, act = [exp, act].map { |x| convert(x, opts[:fmt]) }
  m = HashCmp.new(exp, act)
  assert m.match?,  "#{opts[:fmt].to_s.upcase} documents do not match\n" + m.errors
end
convert(x, fmt) click to toggle source
# File tests/cimi/spec/spec_helper.rb, line 121
def convert(x, fmt)
  if fmt == :json
    x = x.to_json if x.is_a?(CIMI::Model::Base)
    x = JSON.parse(x) if x.is_a?(String)
  elsif fmt == :xml
    x = x.to_xml if x.is_a?(CIMI::Model::Base)
    x = parse_xml(x)  if x.is_a?(String)
  else
    raise "Invalid format #{fmt}"
  end
  x
end