I'm trying to add some extra methods to the time class by opening it up like this:
class Time # opening up ruby time
ONE_DAY_IN_SECS = 86400
def self.yesterday_at_midnight(today = Time.now) time_yesterday = today.to_i - ONE_DAY_IN_SECS yesterday = Time.at( time_yesterday ) return "#{yesterday.year}-#{yesterday.month_with_leading_zero}- #{yesterday.day_with_leading_zero} " end
# ... etc
end
When I run my test from within NetBeans 6.0.1...
require 'test/unit'
class TimeTest < Test::Unit::TestCase
MONDAY_05_05_2008 = 1209972973
def test_can_open_time_to_add_yesterday_at_midnight today = Time.yesterday_at_midnight(Time.at(MONDAY_05_05_2008)) expected = "2008-05-04" assert( expected == today) end
end
This works and I get a passing test.
However if I include an additional require line in my test: require 'unit_test_helper' then I get the following error:
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:92:in `load_specification': undefined method `parse' for Time:Class (NoMethodError) from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb: 314:in `date=' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb: 416:in `send' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb: 416:in `initialize' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb: 412:in `each' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb: 412:in `initialize' from (eval):1:in `new' from (eval):1:in `load_specification' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/source_index.rb: 128:in `eval' ... 11 levels... from C:/ruby/lib/ruby/site_ruby/1.8/rubygems.rb:211:in `synchronize' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems.rb:211:in `searcher' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 30:in `require' from C:/dev/esp/test/unit/models/time_test.rb:2
I think this has something to do with not requiring time properly, but I can't work it out. Has anyone has a similar problem?
Jules