Last active
August 29, 2015 14:13
-
-
Save mattles/89b75a1d3609b0b55c5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gives you a list of all the attributes the do not match up, with their expected results.