timecop 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,6 +1,8 @@
1
1
  # timecop
2
2
 
3
- - Source[http://github.com/jtrupiano/timecop]
3
+ [![Build Status](https://secure.travis-ci.org/travisjeffery/timecop.png)](http://travis-ci.org/travisjeffery/timecop)
4
+
5
+ - Source[http://github.com/travisjeffery/timecop]
4
6
  - Documentation[http://johntrupiano.rubyforge.org/timecop]
5
7
 
6
8
  ## DESCRIPTION
@@ -93,6 +95,8 @@ Time.now
93
95
  # => 2012-09-21 06:22:59 -0500
94
96
  ```
95
97
 
98
+ See #42 for more information, thanks to Ken Mayer, David Holcomb, and Pivotal Labs.
99
+
96
100
  ## REFERENCES
97
101
 
98
102
  * {0.3.4 release}[http://blog.smartlogicsolutions.com/2009/12/07/timecop-0-3-4-released/]
@@ -102,8 +106,8 @@ Time.now
102
106
 
103
107
  ## Contribute
104
108
 
105
- timecop is maintained by [travisjeffery](http://github.com/travisjeffery), who
106
- you can also hit up on [Twitter](http://twitter.com/travisjeffery).
109
+ timecop is maintained by [travisjeffery](http://github.com/travisjeffery), and
110
+ was created by [jtrupiano](https://github.com/jtrupiano).
107
111
 
108
112
  Here's the most direct way to get your work merged into the project.
109
113
 
@@ -1,29 +1,25 @@
1
1
 
2
2
  class Time #:nodoc:
3
3
  class << self
4
- # Time we are behaving as
5
4
  def mock_time
6
5
  mocked_time_stack_item = Timecop.top_stack_item
7
6
  mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.time(self)
8
7
  end
9
8
 
10
- # Alias the original now
11
9
  alias_method :now_without_mock_time, :now
12
10
 
13
- # Define now_with_mock_time
14
11
  def now_with_mock_time
15
12
  mock_time || now_without_mock_time
16
13
  end
17
14
 
18
- # Alias now to now_with_mock_time
19
15
  alias_method :now, :now_with_mock_time
20
16
 
21
17
  alias_method :new_without_mock_time, :new
22
18
 
23
- def new_with_mock_time *args
19
+ def new_with_mock_time(*args)
24
20
  begin
25
21
  raise ArgumentError.new if args.size <= 0
26
- new_without_mock_time *args
22
+ new_without_mock_time(*args)
27
23
  rescue ArgumentError
28
24
  now
29
25
  end
@@ -36,21 +32,17 @@ end
36
32
  if Object.const_defined?(:Date) && Date.respond_to?(:today)
37
33
  class Date #:nodoc:
38
34
  class << self
39
- # Date we are behaving as
40
35
  def mock_date
41
36
  mocked_time_stack_item = Timecop.top_stack_item
42
37
  mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.date(self)
43
38
  end
44
39
 
45
- # Alias the original today
46
40
  alias_method :today_without_mock_date, :today
47
41
 
48
- # Define today_with_mock_date
49
42
  def today_with_mock_date
50
43
  mock_date || today_without_mock_date
51
44
  end
52
45
 
53
- # Alias today to today_with_mock_date
54
46
  alias_method :today, :today_with_mock_date
55
47
  end
56
48
  end
@@ -59,26 +51,19 @@ end
59
51
  if Object.const_defined?(:DateTime) && DateTime.respond_to?(:now)
60
52
  class DateTime #:nodoc:
61
53
  class << self
62
- # Time we are behaving as
63
54
  def mock_time
64
55
  mocked_time_stack_item = Timecop.top_stack_item
65
56
  mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.datetime(self)
66
57
  end
67
58
 
68
- # Fake alias :now_without_mock_time :now
69
- # It appears that the DateTime library itself references Time.now
70
- # for it's interpretation of now which caused
71
- # DateTime.now_without_mock_time to incorrectly return the frozen time.
72
59
  def now_without_mock_time
73
- Time.now_without_mock_time.send :to_datetime
60
+ Time.now_without_mock_time.to_datetime
74
61
  end
75
62
 
76
- # Define now_with_mock_time
77
63
  def now_with_mock_time
78
64
  mock_time || now_without_mock_time
79
65
  end
80
66
 
81
- # Alias now to now_with_mock_time
82
67
  alias_method :now, :now_with_mock_time
83
68
  end
84
69
  end
@@ -3,8 +3,8 @@ class Timecop
3
3
  # A data class for carrying around "time movement" objects. Makes it easy to keep track of the time
4
4
  # movements on a simple stack.
5
5
  class TimeStackItem #:nodoc:
6
-
7
6
  attr_reader :mock_type
7
+
8
8
  def initialize(mock_type, *args)
9
9
  raise "Unknown mock_type #{mock_type}" unless [:freeze, :travel, :scale].include?(mock_type)
10
10
  @scaling_factor = args.shift if mock_type == :scale
@@ -51,13 +51,13 @@ class Timecop
51
51
  @scaling_factor
52
52
  end
53
53
 
54
- def time(time_klass=Time) #:nodoc:
54
+ def time(time_klass = Time) #:nodoc:
55
55
  if travel_offset.nil?
56
- time_klass.at( @time.to_f )
56
+ time_klass.at(@time.to_f)
57
57
  elsif scaling_factor.nil?
58
- time_klass.at( ( Time.now_without_mock_time + travel_offset ).to_f )
58
+ time_klass.at((Time.now_without_mock_time + travel_offset).to_f)
59
59
  else
60
- time_klass.at( scaled_time )
60
+ time_klass.at(scaled_time)
61
61
  end
62
62
  end
63
63
 
@@ -65,17 +65,16 @@ class Timecop
65
65
  (@time + (Time.now_without_mock_time - @time_was) * scaling_factor).to_f
66
66
  end
67
67
 
68
- def date(date_klass=Date)
68
+ def date(date_klass = Date)
69
69
  date_klass.jd(time.__send__(:to_date).jd)
70
70
  end
71
71
 
72
- def datetime(datetime_klass=DateTime)
73
- # DateTime doesn't know about DST, so let's remove its presence
72
+ def datetime(datetime_klass = DateTime)
74
73
  our_offset = utc_offset + dst_adjustment
74
+
75
75
  if Float.method_defined?(:to_r)
76
76
  fractions_of_a_second = time.to_f % 1
77
- datetime_klass.new(year, month, day, hour, min, sec + fractions_of_a_second,
78
- utc_offset_to_rational(our_offset))
77
+ datetime_klass.new(year, month, day, hour, min, sec + fractions_of_a_second, utc_offset_to_rational(our_offset))
79
78
  else
80
79
  our_offset = utc_offset + dst_adjustment
81
80
  datetime_klass.new(year, month, day, hour, min, sec, utc_offset_to_rational(our_offset))
@@ -140,6 +139,5 @@ class Timecop
140
139
  return nil if mock_type == :freeze
141
140
  time - Time.now_without_mock_time
142
141
  end
143
-
144
142
  end
145
143
  end
@@ -47,11 +47,11 @@ class Timecop
47
47
  # which will lead to files being generated with the timestamp set by the Timecop.freeze call
48
48
  # in your dev environment
49
49
  #
50
- # Returns the value of the block or nil.
50
+ # Returns the value of the block if one is given, or the mocked time.
51
51
  def freeze(*args, &block)
52
- val = instance().send(:travel, :freeze, *args, &block)
52
+ val = instance.send(:travel, :freeze, *args, &block)
53
53
 
54
- block_given? ? val : nil
54
+ block_given? ? val : Time.now
55
55
  end
56
56
 
57
57
  # Allows you to run a block of code and "fake" a time throughout the execution of that block.
@@ -60,11 +60,11 @@ class Timecop
60
60
  # * Note: Timecop.travel will not freeze time (as opposed to Timecop.freeze). This is a particularly
61
61
  # good candidate for use in environment files in rails projects.
62
62
  #
63
- # Returns the value of the block or nil.
63
+ # Returns the value of the block if one is given, or the mocked time.
64
64
  def travel(*args, &block)
65
- val = instance().send(:travel, :travel, *args, &block)
65
+ val = instance.send(:travel, :travel, *args, &block)
66
66
 
67
- block_given? ? val : nil
67
+ block_given? ? val : Time.now
68
68
  end
69
69
 
70
70
  # Allows you to run a block of code and "scale" a time throughout the execution of that block.
@@ -74,74 +74,87 @@ class Timecop
74
74
  # end
75
75
  # See Timecop#freeze for exact usage of the other arguments
76
76
  #
77
- # Returns the value of the block or nil.
77
+ # Returns the value of the block if one is given, or the mocked time.
78
78
  def scale(*args, &block)
79
- val = instance().send(:travel, :scale, *args, &block)
79
+ val = instance.send(:travel, :scale, *args, &block)
80
80
 
81
- block_given? ? val : nil
81
+ block_given? ? val : Time.now
82
82
  end
83
83
 
84
84
  def baseline
85
- instance().send(:baseline)
85
+ instance.send(:baseline)
86
86
  end
87
87
 
88
88
  def baseline=(baseline)
89
- instance().send(:baseline=, baseline)
89
+ instance.send(:baseline=, baseline)
90
90
  end
91
91
 
92
- # Reverts back to system's Time.now, Date.today and DateTime.now (if it exists).
93
- def return
94
- instance().send(:unmock!)
95
- nil
92
+ # Reverts back to system's Time.now, Date.today and DateTime.now (if it exists) permamently when
93
+ # no block argument is given, or temporarily reverts back to the system's time temporarily for
94
+ # the given block.
95
+ def return(&block)
96
+ if block_given?
97
+ instance.send(:return, &block)
98
+ else
99
+ instance.send(:unmock!)
100
+ nil
101
+ end
96
102
  end
97
103
 
98
104
  def return_to_baseline
99
- instance().send(:return_to_baseline)
105
+ instance.send(:return_to_baseline)
100
106
  Time.now
101
107
  end
102
108
 
103
109
  def top_stack_item #:nodoc:
104
- instance().instance_variable_get(:@_stack).last
110
+ instance.instance_variable_get(:@_stack).last
105
111
  end
106
112
  end
107
113
 
108
- protected
114
+ private
109
115
 
110
- def baseline=(baseline)
111
- @baseline = baseline
112
- @_stack << TimeStackItem.new(:travel, baseline)
113
- end
116
+ def baseline=(baseline)
117
+ @baseline = baseline
118
+ @_stack << TimeStackItem.new(:travel, baseline)
119
+ end
114
120
 
115
- def initialize #:nodoc:
116
- @_stack = []
117
- end
121
+ def initialize #:nodoc:
122
+ @_stack = []
123
+ end
118
124
 
119
- def travel(mock_type, *args, &block) #:nodoc:
120
- stack_item = TimeStackItem.new(mock_type, *args)
125
+ def travel(mock_type, *args, &block) #:nodoc:
126
+ stack_item = TimeStackItem.new(mock_type, *args)
121
127
 
122
- # store this time traveling on our stack...
123
- @_stack << stack_item
128
+ @_stack << stack_item
124
129
 
125
- if block_given?
126
- begin
127
- yield stack_item.time
128
- ensure
129
- # pull it off the stack...
130
- @_stack.pop
131
- end
130
+ if block_given?
131
+ begin
132
+ yield stack_item.time
133
+ ensure
134
+ @_stack.pop
132
135
  end
133
136
  end
137
+ end
134
138
 
135
- def unmock! #:nodoc:
136
- @baseline = nil
137
- @_stack = []
138
- end
139
+ def return(&block)
140
+ current_stack = @_stack
141
+ current_baseline = @baseline
142
+ unmock!
143
+ yield
144
+ @_stack = current_stack
145
+ @baseline = current_baseline
146
+ end
139
147
 
140
- def return_to_baseline
141
- if @baseline
142
- @_stack = [@_stack.shift]
143
- else
144
- unmock!
145
- end
148
+ def unmock! #:nodoc:
149
+ @baseline = nil
150
+ @_stack = []
151
+ end
152
+
153
+ def return_to_baseline
154
+ if @baseline
155
+ @_stack = [@_stack.shift]
156
+ else
157
+ unmock!
146
158
  end
159
+ end
147
160
  end
@@ -1,3 +1,3 @@
1
1
  class Timecop
2
- VERSION = "0.5.2"
3
- end
2
+ VERSION = "0.5.3"
3
+ end
@@ -3,7 +3,6 @@ require 'test_helper'
3
3
  require File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
4
4
 
5
5
  class TestTimeStackItem < Test::Unit::TestCase
6
-
7
6
  def teardown
8
7
  Timecop.active_support = nil
9
8
  Timecop.return
@@ -13,6 +12,7 @@ class TestTimeStackItem < Test::Unit::TestCase
13
12
  t = Time.now
14
13
  y, m, d, h, min, s = t.year, t.month, t.day, t.hour, t.min, t.sec
15
14
  stack_item = Timecop::TimeStackItem.new(:freeze, t)
15
+
16
16
  assert_equal y, stack_item.year
17
17
  assert_equal m, stack_item.month
18
18
  assert_equal d, stack_item.day
@@ -25,6 +25,7 @@ class TestTimeStackItem < Test::Unit::TestCase
25
25
  t = Time.new(2012, 7, 28, 20, 0)
26
26
  y, m, d, h, min, s = t.year, t.month, t.day, t.hour, t.min, t.sec
27
27
  stack_item = Timecop::TimeStackItem.new(:freeze, t)
28
+
28
29
  assert_equal y, stack_item.year
29
30
  assert_equal m, stack_item.month
30
31
  assert_equal d, stack_item.day
@@ -37,6 +38,7 @@ class TestTimeStackItem < Test::Unit::TestCase
37
38
  t = DateTime.now
38
39
  y, m, d, h, min, s = t.year, t.month, t.day, t.hour, t.min, t.sec
39
40
  stack_item = Timecop::TimeStackItem.new(:freeze, t)
41
+
40
42
  assert_equal y, stack_item.year
41
43
  assert_equal m, stack_item.month
42
44
  assert_equal d, stack_item.day
@@ -49,6 +51,7 @@ class TestTimeStackItem < Test::Unit::TestCase
49
51
  each_timezone do
50
52
  t = DateTime.parse("2009-10-11 00:38:00 +0200")
51
53
  stack_item = Timecop::TimeStackItem.new(:freeze, t)
54
+
52
55
  assert_date_times_equal(t, stack_item.datetime)
53
56
  end
54
57
  end
@@ -57,6 +60,7 @@ class TestTimeStackItem < Test::Unit::TestCase
57
60
  date = Date.today
58
61
  y, m, d, h, min, s = date.year, date.month, date.day, 0, 0, 0
59
62
  stack_item = Timecop::TimeStackItem.new(:freeze, date)
63
+
60
64
  assert_equal y, stack_item.year
61
65
  assert_equal m, stack_item.month
62
66
  assert_equal d, stack_item.day
@@ -72,6 +76,7 @@ class TestTimeStackItem < Test::Unit::TestCase
72
76
  t = Time.now
73
77
  y, m, d, h, min, s = t.year, t.month, t.day, t.hour, t.min, t.sec
74
78
  stack_item = Timecop::TimeStackItem.new(:freeze, 0)
79
+
75
80
  assert_equal y, stack_item.year
76
81
  assert_equal m, stack_item.month
77
82
  assert_equal d, stack_item.day
@@ -83,6 +88,7 @@ class TestTimeStackItem < Test::Unit::TestCase
83
88
  def test_new_with_individual_arguments
84
89
  y, m, d, h, min, s = 2008, 10, 10, 10, 10, 10
85
90
  stack_item = Timecop::TimeStackItem.new(:freeze, y, m, d, h, min, s)
91
+
86
92
  assert_equal y, stack_item.year
87
93
  assert_equal m, stack_item.month
88
94
  assert_equal d, stack_item.day
@@ -104,13 +110,13 @@ class TestTimeStackItem < Test::Unit::TestCase
104
110
  assert_equal Rational(0, 1), a_time_stack_item.send(:utc_offset_to_rational, 0)
105
111
  assert_equal Rational(1, 24), a_time_stack_item.send(:utc_offset_to_rational, 3600)
106
112
  end
107
-
108
- # Ensure DST adjustment is calculated properly for DateTime's
113
+
109
114
  def test_compute_dst_adjustment_for_dst_to_dst
110
115
  Timecop.freeze(DateTime.parse("2009-10-1 00:38:00 -0400"))
111
116
  t = DateTime.parse("2009-10-11 00:00:00 -0400")
112
117
  tsi = Timecop::TimeStackItem.new(:freeze, t)
113
118
  return if !(Time.now.dst? && tsi.time.dst?)
119
+
114
120
  assert_equal 0, tsi.send(:dst_adjustment)
115
121
  end
116
122
 
@@ -119,6 +125,7 @@ class TestTimeStackItem < Test::Unit::TestCase
119
125
  t = DateTime.parse("2009-12-11 00:00:00 -0400")
120
126
  tsi = Timecop::TimeStackItem.new(:freeze, t)
121
127
  return if Time.now.dst? || tsi.time.dst?
128
+
122
129
  assert_equal 0, tsi.send(:dst_adjustment)
123
130
  end
124
131
 
@@ -127,6 +134,7 @@ class TestTimeStackItem < Test::Unit::TestCase
127
134
  t = DateTime.parse("2009-12-11 00:00:00 -0400")
128
135
  tsi = Timecop::TimeStackItem.new(:freeze, t)
129
136
  return if !Time.now.dst? || tsi.time.dst?
137
+
130
138
  assert_equal 60 * 60, tsi.send(:dst_adjustment)
131
139
  end
132
140
 
@@ -135,6 +143,7 @@ class TestTimeStackItem < Test::Unit::TestCase
135
143
  t = DateTime.parse("2009-10-11 00:00:00 -0400")
136
144
  tsi = Timecop::TimeStackItem.new(:freeze, t)
137
145
  return if Time.now.dst? || !tsi.time.dst?
146
+
138
147
  assert_equal -1 * 60 * 60, tsi.send(:dst_adjustment)
139
148
  end
140
149
 
@@ -143,6 +152,7 @@ class TestTimeStackItem < Test::Unit::TestCase
143
152
  Timecop.freeze(DateTime.parse("2009-12-1 00:38:00 -0500"))
144
153
  t = DateTime.parse("2009-10-11 00:00:00 -0400")
145
154
  tsi = Timecop::TimeStackItem.new(:freeze, t)
155
+
146
156
  assert_date_times_equal t, tsi.datetime
147
157
  end
148
158
 
@@ -151,17 +161,17 @@ class TestTimeStackItem < Test::Unit::TestCase
151
161
  t = DateTime.parse("2009-11-30 23:38:00 -0500")
152
162
  tsi = Timecop::TimeStackItem.new(:freeze, t)
153
163
  return if !tsi.time.dst?
164
+
154
165
  assert_date_times_equal t, tsi.datetime
155
166
  assert_equal Date.new(2009, 12, 1), tsi.date
156
167
  end
157
-
158
- # Ensure @travel_offset is set properly
168
+
159
169
  def test_set_travel_offset_for_travel
160
- # Timecop.freeze(2009, 10, 1, 0, 0, 0)
161
170
  t_now = Time.now
162
171
  t = Time.local(2009, 10, 1, 0, 0, 30)
163
172
  expected_offset = t - t_now
164
173
  tsi = Timecop::TimeStackItem.new(:travel, t)
174
+
165
175
  assert_times_effectively_equal expected_offset, tsi.send(:travel_offset), 1, "Offset not calculated correctly"
166
176
  end
167
177
 
@@ -169,6 +179,7 @@ class TestTimeStackItem < Test::Unit::TestCase
169
179
  Timecop.freeze(2009, 10, 1, 0, 0, 0)
170
180
  t = Time.local(2009, 10, 1, 0, 0, 30)
171
181
  tsi = Timecop::TimeStackItem.new(:freeze, t)
182
+
172
183
  assert_equal nil, tsi.send(:travel_offset)
173
184
  end
174
185
 
@@ -177,6 +188,7 @@ class TestTimeStackItem < Test::Unit::TestCase
177
188
  t = Time.local(2009, 10, 1, 0, 0, 30)
178
189
  expected_offset = t - t_now
179
190
  tsi = Timecop::TimeStackItem.new(:scale, 4, t)
191
+
180
192
  assert_times_effectively_equal expected_offset, tsi.send(:travel_offset), 1, "Offset not calculated correctly"
181
193
  assert_equal tsi.send(:scaling_factor), 4, "Scaling factor not set"
182
194
  end
data/test/timecop_test.rb CHANGED
@@ -3,25 +3,20 @@ require 'test_helper'
3
3
  require File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
4
4
 
5
5
  class TestTimecop < Test::Unit::TestCase
6
-
7
- def setup
8
-
9
- end
10
-
11
- # just in case...let's really make sure that Timecop is disabled between tests...
12
6
  def teardown
13
7
  Timecop.return
14
8
  end
15
9
 
16
10
  def test_freeze_changes_and_resets_time
17
- # depending on how we're invoked (individually or via the rake test suite)
18
11
  assert !Time.respond_to?(:zone) || Time.zone.nil?
19
12
 
20
13
  t = Time.local(2008, 10, 10, 10, 10, 10)
21
14
  assert_not_equal t, Time.now
15
+
22
16
  Timecop.freeze(2008, 10, 10, 10, 10, 10) do
23
17
  assert_equal t, Time.now
24
18
  end
19
+
25
20
  assert_not_equal t, Time.now
26
21
  end
27
22
 
@@ -68,6 +63,7 @@ class TestTimecop < Test::Unit::TestCase
68
63
  custom_timeklass = Class.new(Time) do
69
64
  def custom_format_method() strftime('%F') end
70
65
  end
66
+
71
67
  Timecop.freeze(2008, 10, 10, 10, 10, 10) do
72
68
  assert custom_timeklass.now.is_a? custom_timeklass
73
69
  assert Time.now.eql? custom_timeklass.now
@@ -80,6 +76,7 @@ class TestTimecop < Test::Unit::TestCase
80
76
  custom_dateklass = Class.new(Date) do
81
77
  def custom_format_method() strftime('%F') end
82
78
  end
79
+
83
80
  Timecop.freeze(2008, 10, 10, 10, 10, 10) do
84
81
  assert custom_dateklass.today.is_a? custom_dateklass
85
82
  assert Date.today.eql? custom_dateklass.today
@@ -92,6 +89,7 @@ class TestTimecop < Test::Unit::TestCase
92
89
  custom_datetimeklass = Class.new(DateTime) do
93
90
  def custom_format_method() strftime('%F') end
94
91
  end
92
+
95
93
  Timecop.freeze(2008, 10, 10, 10, 10, 10) do
96
94
  assert custom_datetimeklass.now.is_a? custom_datetimeklass
97
95
  assert DateTime.now.eql? custom_datetimeklass.now
@@ -119,6 +117,7 @@ class TestTimecop < Test::Unit::TestCase
119
117
  assert_date_times_equal DateTime.new(2008, 10, 10, 10, 10, 10, local_offset), DateTime.now
120
118
  assert_equal Date.new(2008, 10, 10), Date.today
121
119
  end
120
+
122
121
  assert_not_equal t, Time.now
123
122
  assert_not_equal DateTime.new(2008, 10, 10, 10, 10, 10, local_offset), DateTime.now
124
123
  assert_not_equal Date.new(2008, 10, 10), Date.today
@@ -133,7 +132,6 @@ class TestTimecop < Test::Unit::TestCase
133
132
  Timecop.freeze(t) do
134
133
  assert_date_times_equal t, DateTime.now
135
134
  end
136
- # Undo the original freeze
137
135
  Timecop.return
138
136
  end
139
137
  end
@@ -260,6 +258,11 @@ class TestTimecop < Test::Unit::TestCase
260
258
  end
261
259
  end
262
260
 
261
+ def test_scaling_returns_now_if_no_block_given
262
+ t = Time.local(2008, 10, 10, 10, 10, 10)
263
+ assert_times_effectively_equal t, Timecop.scale(4, t)
264
+ end
265
+
263
266
  def test_freeze_with_utc_time
264
267
  each_timezone do
265
268
  t = Time.utc(2008, 10, 10, 10, 10, 10)
@@ -334,9 +337,22 @@ class TestTimecop < Test::Unit::TestCase
334
337
  assert_nil Time.send(:mock_time)
335
338
  end
336
339
 
337
- def test_travel_time_returns_nil
340
+ def test_travel_time_returns_now_if_no_block_given
338
341
  t_future = Time.local(2030, 10, 10, 10, 10, 10)
339
- assert_nil Timecop.travel(t_future)
342
+ assert_times_effectively_equal t_future, Timecop.travel(t_future)
343
+ end
344
+
345
+ def test_return_temporarily_returns_to_current_time_in_given_block
346
+ time_after_travel = Time.local(1990, 7, 16)
347
+ now = Time.now
348
+
349
+ Timecop.travel(time_after_travel)
350
+
351
+ assert_times_effectively_equal(time_after_travel, Time.now)
352
+ Timecop.return do
353
+ assert_times_effectively_equal(now, Time.now)
354
+ end
355
+ assert_times_effectively_equal(time_after_travel, Time.now)
340
356
  end
341
357
 
342
358
  def test_travel_time_with_block_returns_the_value_of_the_block
@@ -347,9 +363,9 @@ class TestTimecop < Test::Unit::TestCase
347
363
  assert_equal expected, actual
348
364
  end
349
365
 
350
- def test_freeze_time_returns_nil
366
+ def test_freeze_time_returns_now_if_no_block_given
351
367
  t_future = Time.local(2030, 10, 10, 10, 10, 10)
352
- assert_nil Timecop.freeze(t_future)
368
+ assert_times_effectively_equal t_future, Timecop.freeze(t_future)
353
369
  end
354
370
 
355
371
  def test_freeze_time_with_block_returns_the_value_of_the_block
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timecop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -50,9 +50,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
50
  - - ! '>='
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
- segments:
54
- - 0
55
- hash: -1525074573276164628
56
53
  required_rubygems_version: !ruby/object:Gem::Requirement
57
54
  none: false
58
55
  requirements:
@@ -61,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
58
  version: '0'
62
59
  requirements: []
63
60
  rubyforge_project: johntrupiano
64
- rubygems_version: 1.8.10
61
+ rubygems_version: 1.8.23
65
62
  signing_key:
66
63
  specification_version: 3
67
64
  summary: A gem providing "time travel" and "time freezing" capabilities, making it