Cucumber - RSpec matcher

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.

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

Pat M. 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” .

;->

On Mon, Mar 9, 2009 at 6:18 PM, James B. [email protected]
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

At 10:54 -0700 3/9/09, Pat M. 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 M.
http://www.cfcl.com/rdm/resume [email protected]
http://www.cfcl.com/rdm/weblog +1 650-873-7841

Technical editing and writing, programming, and web development

David C. wrote:

No, no, no :slight_smile:

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”.

Sent from my iPhone

On Mar 9, 2009, at 1:56 PM, James B. [email protected] wrote:

Thanks. Although, if I recall correctly then I am advised to use the
form

“x.should be == y” .

No, no, no :slight_smile:

5.should == 5
6.should be > 5

Read them aloud and they.should make(:sense).

Cheers,
David

On Mon, Mar 9, 2009 at 2:48 PM, James B. [email protected]
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?

On Mon, Mar 9, 2009 at 2:32 PM, Rich M. [email protected] wrote:

At 10:54 -0700 3/9/09, Pat M. 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.

On Mon, Mar 9, 2009 at 8:48 PM, James B. [email protected]
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

Aslak Hellesøy wrote:

On Mon, Mar 9, 2009 at 8:48 PM, James B. [email protected]
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:
class Object - RDoc Documentation
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”.