I must be missing something obvious here but I cannot seem to see it. I have this step definition: When /entity named "(.*)" has a legal name "(.*)"/ do |name, legal| myentity = Entity.find_by_entity_common_name!(name.hll_keycase) myentity.entity_legal_name.should equal legal.hll_keycase end Which fails with this: And the entity named "Myuser" has a legal name "Myuser Legal Name" # features/app/models/entities/step_definitions/entity_steps.rb:20 expected #<ActiveSupport::Multibyte::Chars:0x2b4bb29e73d8 @wrapped_string="myuser legal name">, got "myuser legal name" (using .equal?) which to me says that I got what I expected (myuser legal name) but which fails the equality test nonetheless. However, if I switch the test to this: assert_equal(myentity.entity_legal_name,legal.hll_keycase) Then the step definition passes. -- Posted via http://www.ruby-forum.com/.
On Mon, Mar 9, 2009 at 6:18 PM, James Byrne <lists at ruby-forum.com> wrote:> I must be missing something obvious here but I cannot seem to see it. > > I have this step definition: > > When /entity named "(.*)" has a legal name "(.*)"/ do |name, legal| > myentity = Entity.find_by_entity_common_name!(name.hll_keycase) > myentity.entity_legal_name.should equal legal.hll_keycase > end > > Which fails with this: > > And the entity named "Myuser" has a legal name "Myuser Legal Name" > # features/app/models/entities/step_definitions/entity_steps.rb:20 > expected #<ActiveSupport::Multibyte::Chars:0x2b4bb29e73d8 > @wrapped_string="myuser legal name">, got "myuser legal name" (using > .equal?) >Looks like you''re expecting an instance of ActiveSupport::Multibyte::Chars, but actually got an instance of String. I''m not familiar with the ActiveSupport::Multibyte::Chars API, but as a general rule, two object won''t be #equal? unless they have the same type. Aslak> > which to me says that I got what I expected (myuser legal name) but > which fails the equality test nonetheless. > > However, if I switch the test to this: > > assert_equal(myentity.entity_legal_name,legal.hll_keycase) > > Then the step definition passes. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Aslak (::) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090309/3c5e5f22/attachment.html>
Use should == instead of equal. == is equality, equal is object identity. You very rarely want to use equal. >> "foo".equal? "foo" => false >> "foo" == "foo" => true Pat On Mar 9, 2009, at 10:18 AM, James Byrne wrote:> I must be missing something obvious here but I cannot seem to see it. > > I have this step definition: > > When /entity named "(.*)" has a legal name "(.*)"/ do |name, legal| > myentity = Entity.find_by_entity_common_name!(name.hll_keycase) > myentity.entity_legal_name.should equal legal.hll_keycase > end > > Which fails with this: > > And the entity named "Myuser" has a legal name "Myuser Legal Name" > # features/app/models/entities/step_definitions/entity_steps.rb:20 > expected #<ActiveSupport::Multibyte::Chars:0x2b4bb29e73d8 > @wrapped_string="myuser legal name">, got "myuser legal name" (using > .equal?) > > which to me says that I got what I expected (myuser legal name) but > which fails the equality test nonetheless. > > However, if I switch the test to this: > > assert_equal(myentity.entity_legal_name,legal.hll_keycase) > > Then the step definition passes. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Pat Maddox wrote:> Use should == instead of equal. == is equality, equal is object > identity. You very rarely want to use equal. > > >> "foo".equal? "foo" > => false > >> "foo" == "foo" > => true > > PatThanks. Although, if I recall correctly then I am advised to use the form "x.should be == y" . ;-> -- Posted via http://www.ruby-forum.com/.
On Mon, Mar 9, 2009 at 2:32 PM, Rich Morin <rdm at cfcl.com> wrote:> At 10:54 -0700 3/9/09, Pat Maddox wrote: >> Use should == instead of equal. ?== is equality, equal >> is object identity. ?You very rarely want to use equal. > > It''s probably far too late to change this, but it might > have made more sense to define same_obj_as?() for the > object identity case, leaving equal?() available for the > more common test.You''re about two years too late. If I had it to do over again, I''d probably stick with the original version: "this".should equal(this) :this.should be(:this) But changing that back now would result in mutiny. C''est la vie.> > -r > -- > http://www.cfcl.com/rdm ? ? ? ? ? ?Rich Morin > http://www.cfcl.com/rdm/resume ? ? rdm at cfcl.com > http://www.cfcl.com/rdm/weblog ? ? +1 650-873-7841 > > Technical editing and writing, programming, and web development > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Sent from my iPhone On Mar 9, 2009, at 1:56 PM, James Byrne <lists at ruby-forum.com> wrote:> Pat Maddox wrote: >> Use should == instead of equal. == is equality, equal is object >> identity. You very rarely want to use equal. >> >>>> "foo".equal? "foo" >> => false >>>> "foo" == "foo" >> => true >> >> Pat > > Thanks. Although, if I recall correctly then I am advised to use the > form > > "x.should be == y" .No, no, no :) 5.should == 5 6.should be > 5 Read them aloud and they.should make(:sense). Cheers, David> > > ;-> > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
At 10:54 -0700 3/9/09, Pat Maddox wrote:> Use should == instead of equal. == is equality, equal > is object identity. You very rarely want to use equal.It''s probably far too late to change this, but it might have made more sense to define same_obj_as?() for the object identity case, leaving equal?() available for the more common test. -r -- http://www.cfcl.com/rdm Rich Morin http://www.cfcl.com/rdm/resume rdm at cfcl.com http://www.cfcl.com/rdm/weblog +1 650-873-7841 Technical editing and writing, programming, and web development
David Chelimsky wrote:> > No, no, no :) > > 5.should == 5 > 6.should be > 5 > > Read them aloud and they.should make(:sense). > > Cheers, > DavidPerhaps it is my dialect, but what is wrong with: "5 should be equal to 5" which generally is how I read "=="? Actually, I tend to read "==" (in Ruby) as "is equal to". -- Posted via http://www.ruby-forum.com/.
On Mon, Mar 9, 2009 at 2:48 PM, James Byrne <lists at ruby-forum.com> wrote:> David Chelimsky wrote: >> >> No, no, no :) >> >> 5.should == 5 >> 6.should be > 5 >> >> Read them aloud and they.should make(:sense). >> >> Cheers, >> David > > Perhaps it is my dialect, but what is wrong with: > > ? "5 should be equal to 5" > > which generally is how I read "=="? ?Actually, I tend to read "==" (in > Ruby) as "is equal to".Really? Are we still debating this?
On Mon, Mar 9, 2009 at 8:48 PM, James Byrne <lists at ruby-forum.com> wrote:> David Chelimsky wrote: > > > > No, no, no :) > > > > 5.should == 5 > > 6.should be > 5 > > > > Read them aloud and they.should make(:sense). > > > > Cheers, > > David > > Perhaps it is my dialect, but what is wrong with: > > "5 should be equal to 5" > > which generally is how I read "=="? Actually, I tend to read "==" (in > Ruby) as "is equal to".RSpec does - and will - use Ruby''s semantics for equality: http://www.ruby-doc.org/core/classes/Object.html Homemade semantics will not be implemented, as inconsistency with Ruby''s semantics will lead to confusion. Aslak> > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090309/ef5b61ed/attachment.html>
Aslak Helles?y wrote:> On Mon, Mar 9, 2009 at 8:48 PM, James Byrne <lists at ruby-forum.com> > wrote: > >> > David >> >> Perhaps it is my dialect, but what is wrong with: >> >> "5 should be equal to 5" >> >> which generally is how I read "=="? Actually, I tend to read "==" (in >> Ruby) as "is equal to". > > > RSpec does - and will - use Ruby''s semantics for equality: > http://www.ruby-doc.org/core/classes/Object.html > Homemade semantics will not be implemented, as inconsistency with Ruby''s > semantics will lead to confusion.Ruby semantics are not at issue. I read "==" to mean "is equal to" in its English sense and no other, as in "two plus five is equal to seven". -- Posted via http://www.ruby-forum.com/.