0
describe Foo do
  describe 'create' do
    let( :expected_foo ){ Foo.new( name:'foo 1', value:'bar' )}

    it 'succeeds' do
      Foo.create( name:'foo 1', value:'bar' )

      Foo.first.should == expected_foo
    end
  end
end

This test will fail because expected_foo is a different object from the object in the database.

It seems the best way to handle this equality is with a custom matcher. Is it possible to use a custom matcher to overload == ?

B Seven
  • 44,484
  • 66
  • 240
  • 385
  • 1
    Check this question - http://stackoverflow.com/questions/4738439/how-to-test-for-activerecord-object-equality. I think also that if you do `expected_foo = Foo.create( name:'foo 1', value:'bar' )` then `Foo.first.should == expected_foo` – Uri Agassi Apr 28 '14 at 19:43
  • That's pretty helpful. `attributes` might work, but I am not using ActiveRecord. I am using MongoMapper, which doesn't have an `attributes` method...but still need to ignore timestamps... – B Seven Apr 28 '14 at 20:00

0 Answers0