Sha256: f050c1a60d8ad5b9c4c3b36f77da34b9a43fbdfd6c3a7809f6a0a367d44b286f
Contents?: true
Size: 1.42 KB
Versions: 2
Compression:
Stored size: 1.42 KB
Contents
gem 'builder' require 'rforce' include RForce module RForceXmlMatchers class Resemble def initialize(expected) @expected = expected end def matches?(actual) @actual = actual return false if different 'size', @actual.size, @expected.size @expected.each_with_index do |exp_rec, index| act_rec = @actual[index] # Only bother to look at the first <Id> # tag in a (presumably) duplicated set. act_id = first_id(act_rec[:Id]) exp_id = first_id(exp_rec[:Id]) return false if different '<Id>', act_id, exp_id return false if different 'keys', act_rec.keys, exp_rec.keys exp_rec.each do |key, _| unless key == :Id return false if different key, act_rec[key], exp_rec[key] end end end return true end def failure_message_for_should %Q{expected "#{@actual.to_s[0..9]}..." } + %Q{to resemble "#{@expected.to_s[0..9]}...":\n} + @difference end private def first_id(id) id.is_a?(Array) ? id.first : id end def different(name, act, exp) return nil if act == exp @difference = %Q{ for #{name}, got:\n } + %Q{#{act.inspect}\n expected:\n #{exp.inspect}} end end def resemble(expected) Resemble.new(expected) end end RSpec.configure do |config| config.include(RForceXmlMatchers) end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rforce-0.8.1 | spec/spec_helper.rb |
rforce-0.8 | spec/spec_helper.rb |