timecop 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,9 +1,29 @@
1
+ === 0.3.0 / 2009-09-20
2
+
3
+ * API
4
+ * Completely remove Timecop#unset_all (deprecated by Timecop#return in 0.2.0)
5
+ * Return Time.now from #freeze, #travel and #return -- code contributed by Keith Bennett (keithrbennett)
6
+
7
+ * Maintenance
8
+ * Fix bug that left Time#mock_time set in some instances
9
+ * Upped build dependency to jeweler ~> 1.0.2
10
+
11
+ * Documentation
12
+ * Clearer examples in the README, better description in the gemspec
13
+ * Improve RDoc
14
+
1
15
  === 0.2.1 / 2009-03-06
2
16
  * API Changes
3
17
 
4
18
  * Introduced a 5th style of arguments to be passed into #travel and #freeze. Now, if you pass in a single integer value,
5
19
  it will be interpreted as a relative offset in seconds from the current Time.now. Previously this was interpreted as
6
20
  only the year, similar to calling Time.local(2008) --> Jan. 1, 2008. This is no longer the case.
21
+
22
+ * Documentation
23
+
24
+ * Moved to Textile for the README.
25
+
26
+ * Added documentation for the new feature, and fixed a few typos.
7
27
 
8
28
  === 0.2.0 / 2008-12-23
9
29
 
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2008
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,69 @@
1
+ = timecop
2
+
3
+ * http://github.com/jtrupiano/timecop
4
+
5
+ == DESCRIPTION
6
+
7
+ A gem providing "time travel" and "time freezing" capabilities, making it dead simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.
8
+
9
+ == FEATURES
10
+
11
+ * Freeze time to a specific point.
12
+ * Travel back to a specific point in time, but allow time to continue moving forward from there.
13
+ * Timecop api allows arguments to be passed into #freeze and #travel as one of the following:
14
+ * Time instance
15
+ * DateTime instance
16
+ * Date instance
17
+ * individual arguments (year, month, day, hour, minute, second)
18
+ * a single integer argument that is interpreted as an offset in seconds from Time.now
19
+ * Nested calls to Timecop#travel and Timecop#freeze are supported -- each block will maintain its interpretation of now.
20
+
21
+ == USAGE
22
+
23
+ Run a time-sensitive test
24
+
25
+ joe = User.find(1)
26
+ joe.purchase_home()
27
+ assert !joe.mortgage_due?
28
+ # move ahead a month and assert that the mortgage is due
29
+ Timecop.freeze(Date.today + 30) do
30
+ assert joe.mortgage_due?
31
+ end
32
+
33
+ Set the time for the test environment of a rails app -- this is particularly helpful if your whole application is time-sensitive. It allows you to build your test data at a single point in time, and to move in/out of that time as appropriate (within your tests)
34
+
35
+ in config/environments/test.rb
36
+
37
+ config.after_initialize do
38
+ # Set Time.now to September 1, 2008 10:05:00 AM (at this instant), but allow it to move forward
39
+ t = Time.local(2008, 9, 1, 10, 5, 0)
40
+ Timecop.travel(t)
41
+ end
42
+
43
+ === The difference between Timecop.freeze and Timecop.travel
44
+
45
+ #freeze is used to statically mock the concept of now. As your program executes, Time.now will not change unless you make subsequent calls into the Timecop API. #travel, on the other hand, computes an offset between what we currently think Time.now is (recall that we support nested traveling) and the time passed in. It uses this offset to simulate the passage of time. To demonstrate, consider the following code snippets:
46
+
47
+ new_time = Time.local(2008, 9, 1, 12, 0, 0)
48
+ Timecop.freeze(new_time)
49
+ sleep(10)
50
+ new_time == Time.now # ==> true
51
+
52
+ Timecop.return # "turn off" Timecop
53
+ Timecop.travel(new_time)
54
+ sleep(10)
55
+ new_time == Time.now # ==> false
56
+
57
+ == DEPENDENCIES
58
+
59
+ * None
60
+
61
+ == INSTALL
62
+
63
+ * sudo gem install timecop (latest stable version from rubyforge)
64
+ * sudo gem install jtrupiano-timecop (HEAD of the repo from github)
65
+
66
+ == REFERENCES
67
+
68
+ * "0.2.0 release":http://blog.smartlogicsolutions.com/2008/12/24/timecop-2-released-freeze-and-rebase-time-ruby/
69
+ * "0.1.0 release":http://blog.smartlogicsolutions.com/2008/11/19/timecop-freeze-time-in-ruby-for-better-testing/
data/Rakefile CHANGED
@@ -2,18 +2,23 @@ require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
4
 
5
+ gem 'jeweler', '~> 1.2.1'
6
+
5
7
  begin
6
8
  require 'jeweler'
7
9
  Jeweler::Tasks.new do |s|
8
10
  s.name = "timecop"
9
11
  s.rubyforge_project = 'johntrupiano' # if different than lowercase project name
10
- s.description = %q(A gem providing simple ways to temporarily override Time.now, Date.today, and DateTime.now. It provides "time travel" capabilities, making it dead simple to test time-dependent code.)
12
+ s.description = %q(A gem providing "time travel" and "time freezing" capabilities, making it dead simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.)
11
13
  s.summary = s.description # More details later??
12
14
  s.email = "jtrupiano@gmail.com"
13
15
  s.homepage = "http://github.com/jtrupiano/timecop"
14
16
  s.authors = ["John Trupiano"]
15
17
  s.files = FileList["[A-Z]*", "{bin,lib,test}/**/*"]
16
- #s.add_dependency 'schacon-git'
18
+ end
19
+ Jeweler::RubyforgeTasks.new do |rubyforge|
20
+ rubyforge.doc_task = "rdoc"
21
+ rubyforge.remote_doc_path = "timecop"
17
22
  end
18
23
  rescue LoadError
19
24
  puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
@@ -29,3 +34,21 @@ task :test do
29
34
  to automate them.
30
35
  MSG
31
36
  end
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ if File.exist?('VERSION')
41
+ version = File.read('VERSION')
42
+ else
43
+ version = ""
44
+ end
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.options << '--line-numbers' << '--inline-source'
48
+ rdoc.title = "timecop #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('History.txt')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
53
+
54
+ task :default => :test
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
+ :minor: 3
3
+ :patch: 0
2
4
  :major: 0
3
- :minor: 2
4
- :patch: 1
data/lib/timecop.rb CHANGED
@@ -1,3 +1,2 @@
1
- # place gem dependencies here...
2
- #require 'timecop/timecop'
1
+ # Require Timecop
3
2
  require File.join(File.dirname(__FILE__), 'timecop', 'timecop')
@@ -1,11 +1,12 @@
1
1
 
2
- # Simply a data class for carrying around "time movement" objects. Makes it easy to keep track of the time
3
- # movements on a simple stack.
4
- class StackItem
2
+ class Timecop
3
+ # Simply a data class for carrying around "time movement" objects. Makes it easy to keep track of the time
4
+ # movements on a simple stack.
5
+ class StackItem #:nodoc:
5
6
 
6
- attr_reader :mock_type, :year, :month, :day, :hour, :minute, :second
7
- def initialize(mock_type, year, month, day, hour, minute, second)
8
- @mock_type, @year, @month, @day, @hour, @minute, @second = mock_type, year, month, day, hour, minute, second
7
+ attr_reader :mock_type, :year, :month, :day, :hour, :minute, :second
8
+ def initialize(mock_type, year, month, day, hour, minute, second)
9
+ @mock_type, @year, @month, @day, @hour, @minute, @second = mock_type, year, month, day, hour, minute, second
10
+ end
9
11
  end
10
- end
11
-
12
+ end
@@ -1,10 +1,11 @@
1
+ #--
1
2
  # 1. Extensions to the Time, Date, and DateTime objects
2
3
  # 2. Allows us to "freeze" time in our Ruby applications.
3
4
  # 3. This is very useful when your app's functionality is dependent on time (e.g.
4
5
  # anything that might expire). This will allow us to alter the return value of
5
6
  # Date.today, Time.now, and DateTime.now, such that our application code _never_ has to change.
6
7
 
7
- class Time
8
+ class Time #:nodoc:
8
9
  class << self
9
10
  # Time we might be behaving as
10
11
  #attr_reader :mock_time
@@ -50,7 +51,7 @@ class Time
50
51
  end
51
52
 
52
53
  if Object.const_defined?(:Date)
53
- class Date
54
+ class Date #:nodoc:
54
55
  class << self
55
56
  def mock_date
56
57
  now = Time.mock_time
@@ -73,7 +74,7 @@ if Object.const_defined?(:Date)
73
74
  end
74
75
 
75
76
  if Object.const_defined?(:DateTime)
76
- class DateTime
77
+ class DateTime #:nodoc:
77
78
  class << self
78
79
  def mock_time
79
80
  t_now = Time.mock_time
@@ -17,24 +17,23 @@ class Timecop
17
17
  # This is particularly useful for writing test methods where the passage of time is critical to the business
18
18
  # logic being tested. For example:
19
19
  #
20
- # <code>
21
20
  # joe = User.find(1)
22
21
  # joe.purchase_home()
23
22
  # assert !joe.mortgage_due?
24
23
  # Timecop.freeze(2008, 10, 5) do
25
24
  # assert joe.mortgage_due?
26
25
  # end
27
- # </code>
28
26
  #
29
27
  # freeze and travel will respond to several different arguments:
30
28
  # 1. Timecop.freeze(time_inst)
31
29
  # 2. Timecop.freeze(datetime_inst)
32
30
  # 3. Timecop.freeze(date_inst)
33
- # 4. Timecop.freeze(year, month, day, hour=0, minute=0, second=0)
31
+ # 4. Timecop.freeze(offset_in_seconds)
32
+ # 5. Timecop.freeze(year, month, day, hour=0, minute=0, second=0)
34
33
  #
35
34
  # When a block is also passed, Time.now, DateTime.now and Date.today are all reset to their
36
- # previous values. This allows us to nest multiple calls to Timecop.travel and have each block
37
- # maintain it's concept of "now."
35
+ # previous values after the block has finished executing. This allows us to nest multiple
36
+ # calls to Timecop.travel and have each block maintain it's concept of "now."
38
37
  #
39
38
  # * Note: Timecop.freeze will actually freeze time. This can cause unanticipated problems if
40
39
  # benchmark or other timing calls are executed, which implicitly expect Time to actually move
@@ -44,39 +43,41 @@ class Timecop
44
43
  # rails project. Generators will load your environment, including the migration generator,
45
44
  # which will lead to files being generated with the timestamp set by the Timecop.freeze call
46
45
  # in your dev environment
46
+ #
47
+ # Returns the frozen time.
47
48
  def self.freeze(*args, &block)
48
49
  instance().send(:travel, :freeze, *args, &block)
50
+ Time.now
49
51
  end
50
52
 
51
53
  # Allows you to run a block of code and "fake" a time throughout the execution of that block.
52
54
  # See Timecop#freeze for a sample of how to use (same exact usage syntax)
53
55
  #
54
56
  # * Note: Timecop.travel will not freeze time (as opposed to Timecop.freeze). This is a particularly
55
- # good candidate for use in environment files in rails projects.
57
+ # good candidate for use in environment files in rails projects.
58
+ #
59
+ # Returns the 'new' current Time.
56
60
  def self.travel(*args, &block)
57
61
  instance().send(:travel, :move, *args, &block)
62
+ Time.now
58
63
  end
59
64
 
60
65
  # Reverts back to system's Time.now, Date.today and DateTime.now (if it exists). If freeze_all or rebase_all
61
66
  # was never called in the first place, this method will have no effect.
67
+ #
68
+ # Returns Time.now, which is now the real current time.
62
69
  def self.return
63
70
  instance().send(:unmock!)
71
+ Time.now
64
72
  end
65
73
 
66
- # [Deprecated]: See Timecop#return instead.
67
- def self.unset_all
68
- $stderr.puts "Timecop#unset_all is deprecated. Please use Timecop#return instead."
69
- $stderr.flush
70
- self.return
71
- end
72
-
73
74
  protected
74
75
 
75
- def initialize
76
+ def initialize #:nodoc:
76
77
  @_stack = []
77
78
  end
78
79
 
79
- def travel(mock_type, *args, &block)
80
+ def travel(mock_type, *args, &block) #:nodoc:
80
81
  # parse the arguments, build our base time units
81
82
  year, month, day, hour, minute, second = parse_travel_args(*args)
82
83
 
@@ -111,7 +112,8 @@ class Timecop
111
112
  end
112
113
  end
113
114
 
114
- def unmock!
115
+ def unmock! #:nodoc:
116
+ @_stack = []
115
117
  Time.unmock!
116
118
  end
117
119
 
@@ -174,25 +176,3 @@ class Timecop
174
176
  return year, month, day, hour, minute, second
175
177
  end
176
178
  end
177
-
178
- #def with_dates(*dates, &block)
179
- # dates.flatten.each do |date|
180
- # begin
181
- # DateTime.forced_now = case date
182
- # when String: DateTime.parse(date)
183
- # when Time: DateTime.parse(date.to_s)
184
- # else
185
- # date
186
- # end
187
- # Date.forced_today = Date.new(DateTime.forced_now.year,
188
- #DateTime.forced_now.month, DateTime.forced_now.day)
189
- # yield
190
- # rescue Exception => e
191
- # raise e
192
- # ensure
193
- # DateTime.forced_now = nil
194
- # Date.forced_today = nil
195
- # end
196
- # end
197
- #end
198
-
data/test/test_timecop.rb CHANGED
@@ -26,6 +26,30 @@ class TestTimecop < Test::Unit::TestCase
26
26
  assert_not_equal t, Time.now
27
27
  end
28
28
 
29
+ def test_freeze_then_return_unsets_mock_time
30
+ Timecop.freeze(1)
31
+ Timecop.return
32
+ assert_nil Time.send(:mock_time)
33
+ end
34
+
35
+ def test_travel_then_return_unsets_mock_time
36
+ Timecop.travel(1)
37
+ Timecop.return
38
+ assert_nil Time.send(:mock_time)
39
+ end
40
+
41
+ def test_freeze_with_block_unsets_mock_time
42
+ assert_nil Time.send(:mock_time), "test is invalid"
43
+ Timecop.freeze(1) do; end
44
+ assert_nil Time.send(:mock_time)
45
+ end
46
+
47
+ def test_travel_with_block_unsets_mock_time
48
+ assert_nil Time.send(:mock_time), "test is invalid"
49
+ Timecop.travel(1) do; end
50
+ assert_nil Time.send(:mock_time)
51
+ end
52
+
29
53
  def test_recursive_freeze
30
54
  t = Time.local(2008, 10, 10, 10, 10, 10)
31
55
  Timecop.freeze(2008, 10, 10, 10, 10, 10) do
@@ -142,7 +166,6 @@ class TestTimecop < Test::Unit::TestCase
142
166
  end
143
167
  assert((t - Time.now).abs < 2000, "Failed to restore previously-traveled time.")
144
168
  end
145
- assert_nil Time.send(:mock_time)
146
169
  end
147
170
 
148
171
  def test_recursive_travel_then_freeze
@@ -155,7 +178,6 @@ class TestTimecop < Test::Unit::TestCase
155
178
  end
156
179
  assert((t - Time.now).abs < 2000, "Failed to restore previously-traveled time.")
157
180
  end
158
- assert_nil Time.send(:mock_time)
159
181
  end
160
182
 
161
183
  def test_recursive_freeze_then_travel
@@ -169,7 +191,40 @@ class TestTimecop < Test::Unit::TestCase
169
191
  end
170
192
  assert_equal t, Time.now
171
193
  end
172
- assert_nil Time.send(:mock_time)
173
194
  end
174
195
 
196
+ def test_return_values_are_Time_instances
197
+ assert Timecop.freeze.is_a?(Time)
198
+ assert Timecop.travel.is_a?(Time)
199
+ assert Timecop.return.is_a?(Time)
200
+ end
201
+
202
+ def test_travel_time_returns_passed_value
203
+ t_future = Time.local(2030, 10, 10, 10, 10, 10)
204
+ t_travel = Timecop.travel t_future
205
+ assert times_effectively_equal(t_future, t_travel)
206
+ end
207
+
208
+ def test_freeze_time_returns_passed_value
209
+ t_future = Time.local(2030, 10, 10, 10, 10, 10)
210
+ t_frozen = Timecop.freeze t_future
211
+ assert times_effectively_equal(t_future, t_frozen)
212
+ end
213
+
214
+ def test_return_time_returns_actual_time
215
+ t_real = Time.now
216
+ Timecop.freeze Time.local(2030, 10, 10, 10, 10, 10)
217
+ t_return = Timecop.return
218
+ assert times_effectively_equal(t_real, t_return)
219
+ end
220
+
221
+
222
+ private
223
+
224
+ # Tests to see that two times are within the given distance,
225
+ # in seconds, from each other.
226
+ def times_effectively_equal(time1, time2, seconds_interval = 1)
227
+ (time1.to_i - time2.to_i).abs <= seconds_interval
228
+ end
229
+
175
230
  end
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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Trupiano
@@ -9,39 +9,39 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-06 00:00:00 -05:00
12
+ date: 2009-09-20 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: A gem providing simple ways to temporarily override Time.now, Date.today, and DateTime.now. It provides "time travel" capabilities, making it dead simple to test time-dependent code.
16
+ description: A gem providing "time travel" and "time freezing" capabilities, making it dead simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.
17
17
  email: jtrupiano@gmail.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
24
25
  files:
25
26
  - History.txt
26
- - Manifest.txt
27
+ - LICENSE
28
+ - README.rdoc
27
29
  - Rakefile
28
- - README.textile
29
30
  - VERSION.yml
30
- - lib/timecop
31
+ - lib/timecop.rb
31
32
  - lib/timecop/stack_item.rb
32
33
  - lib/timecop/time_extensions.rb
33
34
  - lib/timecop/timecop.rb
34
- - lib/timecop/version.rb
35
- - lib/timecop.rb
36
35
  - test/run_tests.sh
37
36
  - test/test_timecop.rb
38
37
  - test/test_timecop_internals.rb
39
38
  - test/test_timecop_without_date.rb
40
39
  has_rdoc: true
41
40
  homepage: http://github.com/jtrupiano/timecop
41
+ licenses: []
42
+
42
43
  post_install_message:
43
44
  rdoc_options:
44
- - --inline-source
45
45
  - --charset=UTF-8
46
46
  require_paths:
47
47
  - lib
@@ -60,9 +60,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  requirements: []
61
61
 
62
62
  rubyforge_project: johntrupiano
63
- rubygems_version: 1.3.1
63
+ rubygems_version: 1.3.5
64
64
  signing_key:
65
- specification_version: 2
66
- summary: A gem providing simple ways to temporarily override Time.now, Date.today, and DateTime.now. It provides "time travel" capabilities, making it dead simple to test time-dependent code.
67
- test_files: []
68
-
65
+ specification_version: 3
66
+ summary: A gem providing "time travel" and "time freezing" capabilities, making it dead simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.
67
+ test_files:
68
+ - test/test_timecop.rb
69
+ - test/test_timecop_internals.rb
70
+ - test/test_timecop_without_date.rb
data/Manifest.txt DELETED
@@ -1,14 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- README.txt
4
- Rakefile
5
- lib/timecop.rb
6
- lib/timecop/stack_item.rb
7
- lib/timecop/time_extensions.rb
8
- lib/timecop/timecop.rb
9
- lib/timecop/version.rb
10
- test/run_tests.sh
11
- test/test_timecop.rb
12
- test/test_timecop_internals.rb
13
- test/test_timecop_without_date.rb
14
- timecop.gemspec
data/README.textile DELETED
@@ -1,89 +0,0 @@
1
- h1. timecop
2
-
3
- * http://github.com/jtrupiano/timecop
4
-
5
- h2. DESCRIPTION
6
-
7
- A gem providing simple ways to mock Time.now, Date.today, and DateTime.now. It provides "time travel" and "time freezing" capabilities, making it dead simple to test time-dependent code.
8
-
9
- h2. FEATURES
10
-
11
- * Temporarily (or permanently if you prefer) change the concept of Time.now, DateTime.now, and Date.today
12
- * Timecop api allows arguments to be passed into #freeze and #travel as one of the following:
13
- # Time instance
14
- # DateTime instance
15
- # Date instance
16
- # individual arguments (year, month, day, hour, minute, second)
17
- # a single integer argument that is interpreted as an offset in seconds from Time.now
18
-
19
- * Nested calls to Timecop#travel and Timecop#freeze are supported -- each block will maintain it's interpretation of now.
20
-
21
- h2. SHORTCOMINGS
22
-
23
- * Only fully tested on the 1.8.6 Ruby implementations. 1.8.7 and 1.9.1 should be tested, as well as other flavors (jruby, etc.)
24
-
25
- h2. SYNOPSIS
26
-
27
- * Run a time-sensitive test:
28
- <code>
29
- joe = User.find(1)
30
- joe.purchase_home()
31
- assert !joe.mortgage_due?
32
- # move ahead a month and assert that the mortgage is due
33
- Timecop.freeze(Date.today + 30) do
34
- assert joe.mortgage_due?
35
- end
36
- </code>
37
-
38
- * Set the time for the test environment of a rails app -- this is particularly helpful if your whole application
39
- is time-sensitive. It allows you to build your test data at a single point in time, and to move in/out of that
40
- time as appropriate (within your tests)
41
-
42
- in config/environments/test.rb
43
-
44
- <code>
45
- config.after_initialize do
46
- # Set Time.now to September 1, 2008 10:05:00 AM
47
- t = Time.local(2008, 9, 1, 10, 5, 0)
48
- Timecop.travel(t)
49
- end
50
- </code>
51
-
52
- h2. REQUIREMENTS
53
-
54
- * None
55
-
56
- h2. INSTALL
57
-
58
- * sudo gem install timecop (latest stable version from rubyforge)
59
- * sudo gem install jtrupiano-timecop (HEAD of the repo from github)
60
-
61
- h2. REFERENCES
62
-
63
- * http://blog.smartlogicsolutions.com/2008/11/19/timecop-freeze-time-in-ruby-for-better-testing/
64
- * http://blog.smartlogicsolutions.com/2008/12/24/timecop-2-released-freeze-and-rebase-time-ruby/
65
-
66
- h2. LICENSE
67
-
68
- (The MIT License)
69
-
70
- Copyright (c) 2008 FIX
71
-
72
- Permission is hereby granted, free of charge, to any person obtaining
73
- a copy of this software and associated documentation files (the
74
- 'Software'), to deal in the Software without restriction, including
75
- without limitation the rights to use, copy, modify, merge, publish,
76
- distribute, sublicense, and/or sell copies of the Software, and to
77
- permit persons to whom the Software is furnished to do so, subject to
78
- the following conditions:
79
-
80
- The above copyright notice and this permission notice shall be
81
- included in all copies or substantial portions of the Software.
82
-
83
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
84
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
85
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
86
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
87
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
88
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
89
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,20 +0,0 @@
1
- module Timecop
2
- module Version #:nodoc:
3
- # A method for comparing versions of required modules. It expects two
4
- # arrays of integers as parameters, the first being the minimum version
5
- # required, and the second being the actual version available. It returns
6
- # true if the actual version is at least equal to the required version.
7
- def self.check(required, actual) #:nodoc:
8
- required = required.map { |v| "%06d" % v }.join(".")
9
- actual = actual.map { |v| "%06d" % v }.join(".")
10
- return actual >= required
11
- end
12
-
13
- MAJOR = 0
14
- MINOR = 2
15
- TINY = 0
16
-
17
- STRING = [MAJOR, MINOR, TINY].join(".")
18
- end
19
- end
20
-