On Jul 8, 2010, at 5:04 AM, Juanma Cervera wrote: > Hello > How can I test equality with two objects when they include some > attribute that is BigDecimal? > > if I make something like this: > > it "should ...whatever" do > obj = Factory.create(:my_object) > ... > MyObject.first.should == obj > end. > > FAILS > > This fails because the object expected is different from the object > gotten, and the only difference are the BigDecimal attributes, that are > different objects, even though they have the same value.
rspec delegates ==() to the objects being compared. It's up to library providers and users to override ==() in a way that is sane in a given context. Assuming a single BigDecimal attr named amount, something like this: def ==(other) self.attributes.merge(:amount => BigDecimal.new(self.amount.to_s)) == other.attributes.merge(:amount => BigDecimal.new(other.amount.to_s)) end HTH, David _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users