Sha256: 3e4b85cd87c872f889928d90f1d364ca05d12fbe781ac86e0534a74617ce145d
Contents?: true
Size: 1.38 KB
Versions: 20
Compression:
Stored size: 1.38 KB
Contents
module BeModelWithValuesMatcher class BeModelWithValues def initialize(expected_hash, compare_as_strings=false) @compare_as_strings = compare_as_strings @expected_hash = expected_hash end def matches?(model) @model_hash = model.fill_hash(@expected_hash.keys) @diff_keys = @expected_hash.keys - @model_hash.keys @diff_act_values = {} @diff_exp_values = {} return false unless @diff_keys.empty? @model_hash.each do |k,v| model_value = @compare_as_strings ? @model_hash[k].to_s : @model_hash[k] expected_value = @compare_as_strings ? @expected_hash[k].to_s : @expected_hash[k] unless model_value == expected_value @diff_act_values[k] = v @diff_exp_values[k] = @expected_hash[k] end end return @diff_act_values.empty? end def failure_message str = "expected:\n#{@expected_hash.inspect}\n but got:\n#{@model_hash.inspect}" str += "\n\nmissing keys: #{@diff_keys.inspect}" unless @diff_keys.empty? unless @diff_act_values.empty? str += "\n\nunequal values: \nexpected: #{@diff_exp_values.inspect} \n but got:\n#{@diff_act_values.inspect}" end str end end def be_model_with_values(expected) BeModelWithValues.new(expected) end def be_model_with_values_as_strings(expected) BeModelWithValues.new(expected,true) end end
Version data entries
20 entries across 20 versions & 1 rubygems