I’m trying to test a rails, application, and in one particular case, I need to create a TimeWithZone object inside my testcase. So I write sth like this:
started_at = ActiveSupport::TimeWithZone(started_at, Time.zone)
only to get an error:
NoMethodError: undefined method `TimeWithZone' for ActiveSupport:Module
I tried requiring ‘active_support’, ‘active_support/time’, ”active_support/time_with_zone’. each of those statements evaluates to false when I run tests (it works fine in irb)
Any idea on what I’m doing wrong?
Try creating a
newobject:However, you should never need to create instances of this class directly.
If you have Time.zone set up correctly already, you can simply use the
atmethod on it:Take a look at the Rails API documentation for details.