timecop 0.4.6 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,3 +1,18 @@
1
+ === 0.5.0 / 2012-09-12
2
+
3
+ * Maintenance
4
+ * Timecop#travel, Timecop#freeze blocks return nil or block value
5
+
6
+ === 0.4.6 / 2012-09-05
7
+
8
+ * Maintenance
9
+ * Fix rounding support for Ruby < 1.9
10
+
11
+ === 0.4.5 / 2012-08-09
12
+
13
+ * Maintenance
14
+ * Subclasses of Time/Date/DateTime now return proper instances
15
+
1
16
  === 0.4.4 / 2012-07-29
2
17
 
3
18
  * Maintenance
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 6
2
+ :patch: 0
3
3
  :major: 0
4
- :minor: 4
4
+ :minor: 5
@@ -47,10 +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 frozen time.
50
+ # Returns the value of the block or nil.
51
51
  def freeze(*args, &block)
52
- instance().send(:travel, :freeze, *args, &block)
53
- Time.now
52
+ val = instance().send(:travel, :freeze, *args, &block)
53
+
54
+ block_given? ? val : nil
54
55
  end
55
56
 
56
57
  # Allows you to run a block of code and "fake" a time throughout the execution of that block.
@@ -59,10 +60,11 @@ class Timecop
59
60
  # * Note: Timecop.travel will not freeze time (as opposed to Timecop.freeze). This is a particularly
60
61
  # good candidate for use in environment files in rails projects.
61
62
  #
62
- # Returns the 'new' current Time.
63
+ # Returns the value of the block or nil.
63
64
  def travel(*args, &block)
64
- instance().send(:travel, :travel, *args, &block)
65
- Time.now
65
+ val = instance().send(:travel, :travel, *args, &block)
66
+
67
+ block_given? ? val : nil
66
68
  end
67
69
 
68
70
  def baseline
@@ -74,11 +76,9 @@ class Timecop
74
76
  end
75
77
 
76
78
  # Reverts back to system's Time.now, Date.today and DateTime.now (if it exists).
77
- #
78
- # Returns Time.now, which is now the real current time.
79
79
  def return
80
80
  instance().send(:unmock!)
81
- Time.now
81
+ nil
82
82
  end
83
83
 
84
84
  def return_to_baseline
data/test/timecop_test.rb CHANGED
@@ -324,29 +324,34 @@ class TestTimecop < Test::Unit::TestCase
324
324
  assert_nil Time.send(:mock_time)
325
325
  end
326
326
 
327
- def test_return_values_are_Time_instances
328
- assert Timecop.freeze.is_a?(Time)
329
- assert Timecop.travel.is_a?(Time)
330
- assert Timecop.return.is_a?(Time)
327
+ def test_travel_time_returns_nil
328
+ t_future = Time.local(2030, 10, 10, 10, 10, 10)
329
+ assert_nil Timecop.travel(t_future)
330
+ end
331
+
332
+ def test_travel_time_with_block_returns_the_value_of_the_block
333
+ t_future = Time.local(2030, 10, 10, 10, 10, 10)
334
+ expected = :foo
335
+ actual = Timecop.travel(t_future) { expected }
336
+
337
+ assert_equal expected, actual
331
338
  end
332
339
 
333
- def test_travel_time_returns_passed_value
340
+ def test_freeze_time_returns_nil
334
341
  t_future = Time.local(2030, 10, 10, 10, 10, 10)
335
- t_travel = Timecop.travel t_future
336
- assert times_effectively_equal(t_future, t_travel)
342
+ assert_nil Timecop.freeze(t_future)
337
343
  end
338
344
 
339
- def test_freeze_time_returns_passed_value
345
+ def test_freeze_time_with_block_returns_the_value_of_the_block
340
346
  t_future = Time.local(2030, 10, 10, 10, 10, 10)
341
- t_frozen = Timecop.freeze t_future
342
- assert times_effectively_equal(t_future, t_frozen)
347
+ expected = :foo
348
+ actual = Timecop.freeze(t_future) { expected }
349
+
350
+ assert_equal expected, actual
343
351
  end
344
352
 
345
- def test_return_time_returns_actual_time
346
- t_real = Time.now
347
- Timecop.freeze Time.local(2030, 10, 10, 10, 10, 10)
348
- t_return = Timecop.return
349
- assert times_effectively_equal(t_real, t_return)
353
+ def test_return_returns_nil
354
+ assert_nil Timecop.return
350
355
  end
351
356
 
352
357
  def test_freeze_without_params
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timecop
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 6
10
- version: 0.4.6
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Travis Jeffery