strangeness with stubbing in a setup block

10 views
Skip to first unread message

patrick99e99

unread,
Aug 30, 2011, 5:30:53 PM8/30/11
to mocha-developer
Hi everyone,

I am using test unit with shoulda and mocha... I discovered a very
weird thing:

setup do
I18n.stubs(:t).returns({:foo => {:bar => {:lol => "omg"} } })
end

should "do something" do
assert my_method
end

should "do something else" do
assert my_method
end

... When my_method called I18n, it was failing, and when I inspected
it, it appeared to be:

{"foo"=>"barlolomg"}

And the 2nd test would pass, and when inspecting it, it would be as it
should:

{:foo => {:bar => {:lol => "omg"} } }

...

Does anyone know why I got this odd behavior? The only way I could
get this to work was to not use a setup block:

should "do something" do
stub_i18n
assert my_method
end

should "do something else" do
stub_i18n
assert my_method
end

def stub_i18n
I18n.stubs(:t).returns({:foo => {:bar => {:lol => "omg"} } })
end

-patrick

James Mead

unread,
Aug 31, 2011, 4:53:43 AM8/31/11
to mocha-d...@googlegroups.com, mocha-developer
Hi Patrick,

I'm sorry, I'm not near a computer at the moment, so can I ask whether you've tried to narrow down the problem any further e.g. does the same thing happen if you stub a different method on I18n, or if you stub a method on a different class, or if you use Test::Unit without Shoulda?

Can you create a single Ruby file which demonstrates the problem with as few dependencies as possible? i.e. a file any of us could run locally and see the problem for ourselves. It would also be helpful to tell us as much as possible about your environment e.g. OS version, Ruby version, Mocha version and versions of any dependencies.

Regards, James.

> --
> You received this message because you are subscribed to the Google Groups "mocha-developer" group.
> To post to this group, send email to mocha-d...@googlegroups.com.
> To unsubscribe from this group, send email to mocha-develop...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mocha-developer?hl=en.
>

James Mead

unread,
Sep 1, 2011, 5:35:22 AM9/1/11
to mocha-d...@googlegroups.com
Hi Patrick. I just tried to reproduce the problem you described, but I haven't had any luck with the information you've provided so far. Cheers, James.
Reply all
Reply to author
Forward
0 new messages