Skip to content

Instantly share code, notes, and snippets.

@mattles
Last active August 29, 2015 14:13
Show Gist options
  • Save mattles/89b75a1d3609b0b55c5b to your computer and use it in GitHub Desktop.
Save mattles/89b75a1d3609b0b55c5b to your computer and use it in GitHub Desktop.
let(:organisation_customer) do
{
notes: "hot shot lawyer" ,
staff_member_uuid: staff_member.uuid,
created_at: DateTime.now.to_s,
email: customer.email,
name: customer.name,
uuid: "123456"
}
end
it "assigns the params" do
expect(subject.reload).to match_attributes(organisation_customer)
end
RSpec::Matchers.define :match_attributes do |params|
match do |model|
params.map do |attr, param|
!model.respond_to?(attr) || model.try(attr) == param
end.all?
end
failure_message do |model|
message = "#{model.class} attributes not updated correctly: "
params.each do |attr, param|
next unless model.respond_to?(attr)
res = model.try(attr)
message << "\n\t#{model.class}##{attr} should be \"#{param}\" but was \"#{res}\"" unless res == param
end
message
end
end
@mattles
Copy link
Author

mattles commented Jan 21, 2015

This gives you a list of all the attributes the do not match up, with their expected results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment