timecop 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/timecop.rb +2 -2
- data/lib/timecop/timecop.rb +11 -11
- data/lib/timecop/version.rb +1 -1
- data/test/test_helper.rb +5 -1
- data/test/time_stack_item_test.rb +1 -1
- data/test/timecop_test.rb +7 -1
- data/test/timecop_without_date_test.rb +1 -1
- metadata +30 -40
data/lib/timecop.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require File.join(File.dirname(__FILE__), "timecop", "timecop")
|
2
|
+
require File.join(File.dirname(__FILE__), "timecop", "version")
|
data/lib/timecop/timecop.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'singleton'
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require File.join(File.dirname(__FILE__), "time_extensions")
|
3
|
+
require File.join(File.dirname(__FILE__), "time_stack_item")
|
4
4
|
|
5
5
|
# Timecop
|
6
6
|
# * Wrapper class for manipulating the extensions to the Time, Date, and DateTime objects
|
@@ -49,9 +49,7 @@ class Timecop
|
|
49
49
|
#
|
50
50
|
# Returns the value of the block if one is given, or the mocked time.
|
51
51
|
def freeze(*args, &block)
|
52
|
-
|
53
|
-
|
54
|
-
block_given? ? val : Time.now
|
52
|
+
send_travel(:freeze, *args, &block)
|
55
53
|
end
|
56
54
|
|
57
55
|
# Allows you to run a block of code and "fake" a time throughout the execution of that block.
|
@@ -62,9 +60,7 @@ class Timecop
|
|
62
60
|
#
|
63
61
|
# Returns the value of the block if one is given, or the mocked time.
|
64
62
|
def travel(*args, &block)
|
65
|
-
|
66
|
-
|
67
|
-
block_given? ? val : Time.now
|
63
|
+
send_travel(:travel, *args, &block)
|
68
64
|
end
|
69
65
|
|
70
66
|
# Allows you to run a block of code and "scale" a time throughout the execution of that block.
|
@@ -76,9 +72,7 @@ class Timecop
|
|
76
72
|
#
|
77
73
|
# Returns the value of the block if one is given, or the mocked time.
|
78
74
|
def scale(*args, &block)
|
79
|
-
|
80
|
-
|
81
|
-
block_given? ? val : Time.now
|
75
|
+
send_travel(:scale, *args, &block)
|
82
76
|
end
|
83
77
|
|
84
78
|
def baseline
|
@@ -109,6 +103,12 @@ class Timecop
|
|
109
103
|
def top_stack_item #:nodoc:
|
110
104
|
instance.instance_variable_get(:@_stack).last
|
111
105
|
end
|
106
|
+
|
107
|
+
private
|
108
|
+
def send_travel(mock_type, *args, &block)
|
109
|
+
val = instance.send(:travel, mock_type, *args, &block)
|
110
|
+
block_given? ? val : Time.now
|
111
|
+
end
|
112
112
|
end
|
113
113
|
|
114
114
|
private
|
data/lib/timecop/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/timecop_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'date'
|
2
|
-
require
|
2
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
3
3
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
|
4
4
|
|
5
5
|
class TestTimecop < Test::Unit::TestCase
|
@@ -429,4 +429,10 @@ class TestTimecop < Test::Unit::TestCase
|
|
429
429
|
assert_equal date, Time.now
|
430
430
|
assert_equal date, Time.new
|
431
431
|
end
|
432
|
+
|
433
|
+
def test_not_callable_send_travel
|
434
|
+
assert_raise NoMethodError do
|
435
|
+
Timecop.send_travel(:travel, Time.now - 100)
|
436
|
+
end
|
437
|
+
end
|
432
438
|
end
|
metadata
CHANGED
@@ -1,34 +1,27 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: timecop
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 5
|
8
|
-
- 4
|
9
|
-
version: 0.5.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.5
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Travis Jeffery
|
13
9
|
- John Trupiano
|
14
10
|
autorequire:
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2012-11-29 00:00:00 -05:00
|
19
|
-
default_executable:
|
13
|
+
date: 2012-12-20 00:00:00.000000000 Z
|
20
14
|
dependencies: []
|
21
|
-
|
22
|
-
|
15
|
+
description: A gem providing "time travel" and "time freezing" capabilities, making
|
16
|
+
it dead simple to test time-dependent code. It provides a unified method to mock
|
17
|
+
Time.now, Date.today, and DateTime.now in a single call.
|
23
18
|
email: travisjeffery@gmail.com
|
24
19
|
executables: []
|
25
|
-
|
26
20
|
extensions: []
|
27
|
-
|
28
|
-
extra_rdoc_files:
|
21
|
+
extra_rdoc_files:
|
29
22
|
- LICENSE
|
30
23
|
- README.markdown
|
31
|
-
files:
|
24
|
+
files:
|
32
25
|
- History.rdoc
|
33
26
|
- LICENSE
|
34
27
|
- README.markdown
|
@@ -44,37 +37,34 @@ files:
|
|
44
37
|
- test/timecop_test.rb
|
45
38
|
- test/timecop_without_date_test.rb
|
46
39
|
- test/timecop_without_date_but_with_time_test.rb
|
47
|
-
has_rdoc: true
|
48
40
|
homepage: https://github.com/travisjeffery/timecop
|
49
41
|
licenses: []
|
50
|
-
|
51
42
|
post_install_message:
|
52
|
-
rdoc_options:
|
43
|
+
rdoc_options:
|
53
44
|
- --charset=UTF-8
|
54
|
-
require_paths:
|
45
|
+
require_paths:
|
55
46
|
- lib
|
56
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
|
68
|
-
- 0
|
69
|
-
version: "0"
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
70
59
|
requirements: []
|
71
|
-
|
72
60
|
rubyforge_project: timecop
|
73
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.8.23
|
74
62
|
signing_key:
|
75
63
|
specification_version: 3
|
76
|
-
summary: A gem providing "time travel" and "time freezing" capabilities, making it
|
77
|
-
|
64
|
+
summary: A gem providing "time travel" and "time freezing" capabilities, making it
|
65
|
+
dead simple to test time-dependent code. It provides a unified method to mock Time.now,
|
66
|
+
Date.today, and DateTime.now in a single call.
|
67
|
+
test_files:
|
78
68
|
- test/test_helper.rb
|
79
69
|
- test/time_stack_item_test.rb
|
80
70
|
- test/timecop_test.rb
|