for comparing objects properties, which notation is considered most idiomatic and best practice? Thanks, Jed Schneider -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110720/338b70b6/attachment-0001.html>
David Chelimsky
2011-Jul-20 17:11 UTC
[rspec-users] eq or == which is the preferred idiom?
On Jul 20, 2011, at 11:29 AM, Jed Schneider wrote:> for comparing objects properties, which notation is considered most idiomatic and best practice?Traditionally it was ==, but Ruby emits a warning. I''ve personally been moving toward eq, and if I had it to do over again that''s all that would be there. I have no intention, however, of deprecating == as there is a wealth of code out there that uses it and users who prefer it in spite of the warning from Ruby. HTH, David
On Wed, Jul 20, 2011 at 10:29 AM, Jed Schneider <jed.schneider at gmail.com>wrote:> for comparing objects properties, which notation is considered most > idiomatic and best practice? > > Thanks, > > Jed Schneider > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >`eq` uses `==` under the hood. `eq` is the idiomatic approach for two reasons I can think of: 1.) It is more readable 2.) It is part of the "equality" DSL: `eq`, `eql`, `equal`. More info here: http://relishapp.com/rspec/rspec-expectations/v/2-6/dir/built-in-matchers/equality-matchers -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110720/775ccff4/attachment.html>
On 20 Jul 2011, at 18:18, Justin Ko wrote:> > > On Wed, Jul 20, 2011 at 10:29 AM, Jed Schneider <jed.schneider at gmail.com> wrote: > for comparing objects properties, which notation is considered most idiomatic and best practice? > > Thanks, > > Jed Schneider > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > `eq` uses `==` under the hood. `eq` is the idiomatic approach for two reasons I can think of: > > 1.) It is more readable > 2.) It is part of the "equality" DSL: `eq`, `eql`, `equal`. > > More info here: http://relishapp.com/rspec/rspec-expectations/v/2-6/dir/built-in-matchers/equality-matchersI recently discovered eq, and one thing I like is that you can pass a custom failure message, as you could with a traditional assert: "foo".should eq("bar"), "what is wrong with your foo?" I expect this is also possible with == but it would look ugly. cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/books/hwcuc/the-cucumber-book (with Aslak Helles?y) Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110720/8a541f3f/attachment.html>