Sha256: 26558397c5b3a76e37912f162138ee5f692310d126be4d5620667048a9fd1039
Contents?: true
Size: 1.41 KB
Versions: 109
Compression:
Stored size: 1.41 KB
Contents
module BeModelWithValuesMatcher class BeModelWithValues def initialize(expected_hash, compare_as_strings=false) @compare_as_strings = compare_as_strings @expected_hash = expected_hash.stringify_keys! end def matches?(model) @model_hash = model.fill_hash(@expected_hash.keys).stringify_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
109 entries across 109 versions & 1 rubygems