Forum: RSpec Cucumber - RSpec matcher

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-03-09 18:18
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.
39100495c9937c39b2e0c704444e1b4a?d=identicon&s=25 Pat Maddox (Guest)
on 2009-03-09 19:26
(Received via mailing list)
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
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-03-09 19:56
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" .

;->
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-03-09 20:00
(Received via mailing list)
On Mon, Mar 9, 2009 at 6:18 PM, James Byrne <lists@ruby-forum.com>
wrote:

>
>    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
D4d28bd014f9e7324bad99dcc3b0d390?d=identicon&s=25 Rich Morin (Guest)
on 2009-03-09 20:06
(Received via mailing list)
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@cfcl.com
http://www.cfcl.com/rdm/weblog     +1 650-873-7841

Technical editing and writing, programming, and web development
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-03-09 20:23
(Received via mailing list)
Sent from my iPhone

On Mar 9, 2009, at 1:56 PM, James Byrne <lists@ruby-forum.com> wrote:

>
> 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
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-03-09 20:48
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".
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-03-09 22:54
(Received via mailing list)
On Mon, Mar 9, 2009 at 2:48 PM, James Byrne <lists@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".

Really? Are we still debating this?
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-03-10 00:41
(Received via mailing list)
On Mon, Mar 9, 2009 at 8:48 PM, James Byrne <lists@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.

Aslak
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-03-10 13:12
(Received via mailing list)
On Mon, Mar 9, 2009 at 2:32 PM, Rich Morin <rdm@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.
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-03-10 17:46
Aslak Hellesøy wrote:
> On Mon, Mar 9, 2009 at 8:48 PM, James Byrne <lists@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".
This topic is locked and can not be replied to.