Skip to content

Commit

Permalink
rename Timecop#lens -> Timecop#scale (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Jeffery committed Sep 21, 2012
1 parent 6942d0e commit 3854a84
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/timecop/time_stack_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class TimeStackItem #:nodoc:

attr_reader :mock_type
def initialize(mock_type, *args)
raise "Unknown mock_type #{mock_type}" unless [:freeze, :travel, :lens].include?(mock_type)
@scaling_factor = args.shift if mock_type == :lens
raise "Unknown mock_type #{mock_type}" unless [:freeze, :travel, :scale].include?(mock_type)
@scaling_factor = args.shift if mock_type == :scale
@mock_type = mock_type
@time = parse_time(*args)
@time_was = Time.now_without_mock_time
Expand Down
8 changes: 4 additions & 4 deletions lib/timecop/timecop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ def travel(*args, &block)
block_given? ? val : nil
end

# Allows you to run a block of code and "lens" a time throughout the execution of that block.
# Allows you to run a block of code and "scale" a time throughout the execution of that block.
# The first argument is a scaling factor, for example:
# Timecop.lens(2) do
# Timecop.scale(2) do
# ... time will 'go' twice as fast here
# end
# See Timecop#freeze for exact usage of the other arguments
#
# Returns the value of the block or nil.
def lens(*args, &block)
val = instance().send(:travel, :lens, *args, &block)
def scale(*args, &block)
val = instance().send(:travel, :scale, *args, &block)

block_given? ? val : nil
end
Expand Down
2 changes: 1 addition & 1 deletion test/time_stack_item_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_set_scaling_factor_for_lens
t_now = Time.now
t = Time.local(2009, 10, 1, 0, 0, 30)
expected_offset = t - t_now
tsi = Timecop::TimeStackItem.new(:lens, 4, t)
tsi = Timecop::TimeStackItem.new(:scale, 4, t)
assert_times_effectively_equal expected_offset, tsi.send(:travel_offset), 1, "Offset not calculated correctly"
assert_equal tsi.send(:scaling_factor), 4, "Scaling factor not set"
end
Expand Down
2 changes: 1 addition & 1 deletion test/timecop_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def test_mocked_date_time_now_is_local

def test_lensing_keeps_time_moving_at_an_accelerated_rate
t = Time.local(2008, 10, 10, 10, 10, 10)
Timecop.lens(4, t) do
Timecop.scale(4, t) do
start = Time.now
assert_times_effectively_equal start, t, 1, "Looks like we failed to actually travel time"
sleep(0.25)
Expand Down

0 comments on commit 3854a84

Please sign in to comment.