Brent Miller wrote:
> in your test_helper:
>
> require 'mocha'
>
> Then, in your test
>
> def test_something
> tz = :local
> ActiveRecord::Base.expects(:default_timezone).returns(tz)
> assert_equal tz, ActiveRecord::Base.default_timezone
> end
>
> The trick is to set tz to be whatever you want to get back from
> AR::Base.default_timezone. If you use AR::Base.expects, then your
> test will fail if AR::Base.default_timezone is called more than once
> or not at all. If you don't care how many times it gets called (i.e.,
> if that's not something you need to test), then use "AR::Base.stubs
> (:default_timezone).returns(tz)" instead.
>
However, what I am testing is a library that actually modifies
ActiveRecord behaviour based on the default_timezone setting. So, it is
pointless to mock or stub what I am actually testing. I eventually just
overrode the environment setting in the test itself.
it "should set the UTC time (for _at/_on) correctly" do
ActiveRecord::Base.default_timezone = "utc"
...
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---