Sha256: f49be07bf844fb6b7b145fb7e1e89b59ad2f4c6c907811251f6c94e8897bf6d9

Contents?: true

Size: 709 Bytes

Versions: 6

Compression:

Stored size: 709 Bytes

Contents

require 'rspec/expectations'

RSpec::Matchers.define :have_attributes do |expected|
  match do |actual|
    result = true
    expected.each do |key, value|
      result = false unless actual.send(key) == value
    end

    result
  end

  failure_message_for_should do |actual|
    wrong_fields = {}
    expected.each do |key, value|
      wrong_fields[key] = {
        actual: actual.send(key),
        expected: value
      } unless actual.send(key) == value
    end

    wrong_fields.inject("In #{actual.class.name} ") do |message, wrong_field|
      key, value = wrong_field
      message << "expected that #{key} would be #{value[:expected]}, but was #{value[:actual]}\n"
      message
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sandi_meter-1.1.8 spec/support/attr_matcher.rb
sandi_meter-1.1.7 spec/support/attr_matcher.rb
sandi_meter-1.1.6 spec/support/attr_matcher.rb
sandi_meter-1.1.5 spec/support/attr_matcher.rb
sandi_meter-1.0.5 spec/support/attr_matcher.rb
sandi_meter-1.0.4 spec/support/attr_matcher.rb