I'm encountering a strange issue while running a test (Steak + Capybara) that requests a certain page where I get the error:
undefined method parse for Time:Class
The method call occurs in a Sunspot file called type.rb
:
def value_to_utc_time(value)
if value.respond_to?(:utc)
value.utc
elsif value.respond_to?(:new_offset)
value.new_offset
else
begin
Time.parse(value.to_s).utc
rescue ArgumentError
DateTime.parse(value.to_s).new_offset
end
end
end
When I run my server in RAILS_ENV=test
, I get the same error. When I run the server in development, everything is fine and dandy. This would seem to indicate that it's not just my test framework, but the whole test environment that's promoting this error.
The only info I could find online so far about Time.parse
being undefined has been quite unhelpful, with most people saying that adding require 'time'
will solve the problem.
My problems with this are twofold:
- It's hacky
- I've tried it in various places (in
config/environments/test.rb
, in the test file itself, etc.), and it just doesn't work.
If anyone has any ideas what is going on, I welcome them!