parameter matching and symbols vs strings

6 views
Skip to first unread message

Curran

unread,
Oct 6, 2009, 8:45:25 AM10/6/09
to mocha-developer
Hi,

Could you tell me whether the following is "expected behavior" for
Mocha?

Equals.matches?({"first_name" => "John"}) returns false when
Equals.@value = {:first_name => "John"}

I understand why it is failing (symbols do not ==, equal? or eql?
strings) but am wondering whether it is worth implementing a
workaround.

This is a problem in the context of testing that Person.create was
invoked with the right parameters. Somewhere in the controller, my
parameter hash of symbols => strings gets converted into a hash of
strings => strings. It wasn't an issue until I started using Mocha.

A small issue, I know :) Just curious, as it has probably bitten other
developers.

Curran

James Mead

unread,
Oct 6, 2009, 10:38:35 AM10/6/09
to mocha-d...@googlegroups.com
2009/10/6 Curran <c.schie...@gmail.com>:

Hi Curran,

I believe this is expected behaviour. I suspect there's some
Rails-specific fun with HashWithIndifferentAccess [1] going on here.

If you post your test and controller action code, we might be able to
see if there's a better way of doing what you want to do.

Regards, James.

[1] http://api.rubyonrails.org/classes/HashWithIndifferentAccess.html

Curran Schiefelbein

unread,
Oct 6, 2009, 9:00:58 PM10/6/09
to mocha-d...@googlegroups.com
Well, in my test, I switched my params hash over to a string => string hash before feeding it into the controller. Now the comparison passes muster, and nothing else broke, so I'm ok :)

Thanks for confirming that this is "normal" behavior!

Curran
Reply all
Reply to author
Forward
0 new messages