Skip to content

Commit

Permalink
tests for Date/Time/DateTime subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
yaauie committed Aug 9, 2012
1 parent 7c6f531 commit c87ffc3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
timecop (0.4.3)
timecop (0.4.4)

GEM
remote: https://rubygems.org/
Expand Down
36 changes: 36 additions & 0 deletions test/timecop_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,42 @@ def test_travel_does_not_reduce_precision_of_datetime
assert_not_equal DateTime.now, DateTime.now
end

def test_freeze_in_time_subclass_returns_mocked_subclass
t = Time.local(2008, 10, 10, 10, 10, 10)
custom_timeklass = Class.new(Time) do
def custom_format_method() strftime('%F') end
end
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
assert custom_timeklass.now.is_a? custom_timeklass
assert Time.now.eql? custom_timeklass.now
assert custom_timeklass.now.respond_to? :custom_format_method
end
end

def test_freeze_in_date_subclass_returns_mocked_subclass
t = Time.local(2008, 10, 10, 10, 10, 10)
custom_dateklass = Class.new(Date) do
def custom_format_method() strftime('%F') end
end
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
assert custom_dateklass.today.is_a? custom_dateklass
assert Date.today.eql? custom_dateklass.today
assert custom_dateklass.today.respond_to? :custom_format_method
end
end

def test_freeze_in_datetime_subclass_returns_mocked_subclass
t = Time.local(2008, 10, 10, 10, 10, 10)
custom_datetimeklass = Class.new(DateTime) do
def custom_format_method() strftime('%F') end
end
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
assert custom_datetimeklass.now.is_a? custom_datetimeklass
assert DateTime.now.eql? custom_datetimeklass.now
assert custom_datetimeklass.now.respond_to? :custom_format_method
end
end

def test_recursive_freeze
t = Time.local(2008, 10, 10, 10, 10, 10)
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
Expand Down

0 comments on commit c87ffc3

Please sign in to comment.