timecop 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,10 @@
1
+ === 0.2.1 / 2009-03-06
2
+ * API Changes
3
+
4
+ * Introduced a 5th style of arguments to be passed into #travel and #freeze. Now, if you pass in a single integer value,
5
+ it will be interpreted as a relative offset in seconds from the current Time.now. Previously this was interpreted as
6
+ only the year, similar to calling Time.local(2008) --> Jan. 1, 2008. This is no longer the case.
7
+
1
8
  === 0.2.0 / 2008-12-23
2
9
 
3
10
  * API Changes
@@ -1,23 +1,28 @@
1
- = timecop
1
+ h1. timecop
2
2
 
3
3
  * http://github.com/jtrupiano/timecop
4
4
 
5
- == DESCRIPTION:
5
+ h2. DESCRIPTION
6
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 write test time-dependent code.
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
8
 
9
- == FEATURES:
9
+ h2. FEATURES
10
10
 
11
11
  * Temporarily (or permanently if you prefer) change the concept of Time.now, DateTime.now, and Date.today
12
- * Timecop api allows an arguments to be passed into #freeze and #travel as one of: 1) Time instance, 2) DateTime instance, 3) Date instance,
13
- 4) individual arguments (year, month, day, hour, minute, second)
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
+
14
19
  * Nested calls to Timecop#travel and Timecop#freeze are supported -- each block will maintain it's interpretation of now.
15
20
 
16
- == SHORTCOMINGS:
21
+ h2. SHORTCOMINGS
17
22
 
18
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.)
19
24
 
20
- == SYNOPSIS:
25
+ h2. SYNOPSIS
21
26
 
22
27
  * Run a time-sensitive test:
23
28
  <code>
@@ -44,16 +49,21 @@ config.after_initialize do
44
49
  end
45
50
  </code>
46
51
 
47
- == REQUIREMENTS:
52
+ h2. REQUIREMENTS
48
53
 
49
54
  * None
50
55
 
51
- == INSTALL:
56
+ h2. INSTALL
52
57
 
53
58
  * sudo gem install timecop (latest stable version from rubyforge)
54
59
  * sudo gem install jtrupiano-timecop (HEAD of the repo from github)
55
60
 
56
- == LICENSE:
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
57
67
 
58
68
  (The MIT License)
59
69
 
data/Rakefile CHANGED
@@ -1,36 +1,24 @@
1
- # -*- ruby -*-
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
2
4
 
3
- require 'rubygems'
4
- require 'hoe'
5
- require './lib/timecop/version.rb'
6
-
7
- PKG_NAME = "timecop"
8
- PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
9
- version = Timecop::Version::STRING.dup
10
- if ENV['SNAPSHOT'].to_i == 1
11
- version << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
12
- end
13
- PKG_VERSION = version
14
- PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
15
-
16
- Hoe.new(PKG_NAME, PKG_VERSION) do |p|
17
- p.rubyforge_name = 'johntrupiano' # if different than lowercase project name
18
- p.developer('John Trupiano', 'jtrupiano@gmail.com')
19
- p.name = PKG_NAME
20
- p.version = PKG_VERSION
21
- #p.platform = Gem::Platform::RUBY
22
- p.author = "John Trupiano"
23
- p.email = "jtrupiano@gmail.com"
24
- p.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 write test time-dependent code.)
25
- p.summary = p.description # More details later??
26
- p.remote_rdoc_dir = PKG_NAME # Release to /PKG_NAME
27
- # p.changes = p.paragraphs_of('CHANGELOG', 0..1).join("\n\n")
28
- p.need_zip = true
29
- p.need_tar = false
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |s|
8
+ s.name = "timecop"
9
+ 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.)
11
+ s.summary = s.description # More details later??
12
+ s.email = "jtrupiano@gmail.com"
13
+ s.homepage = "http://github.com/jtrupiano/timecop"
14
+ s.authors = ["John Trupiano"]
15
+ s.files = FileList["[A-Z]*", "{bin,lib,test}/**/*"]
16
+ #s.add_dependency 'schacon-git'
17
+ end
18
+ rescue LoadError
19
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
30
20
  end
31
21
 
32
- # vim: syntax=Ruby
33
-
34
22
  # Override the test task and instruct them how to actually run the tests.
35
23
  Rake.application.send(:eval, "@tasks.delete('test')")
36
24
  desc "Does not execute tests. Manually run shell script ./run_tests.sh to execute tests."
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 2
4
+ :patch: 1
@@ -160,6 +160,9 @@ class Timecop
160
160
  elsif Object.const_defined?(:Date) && arg.is_a?(Date)
161
161
  year, month, day, hour, minute, second = arg.year, arg.month, arg.day, 0, 0, 0
162
162
  #puts "#{year}-#{month}-#{day} #{hour}:#{minute}:#{second}"
163
+ elsif args.empty? && arg.kind_of?(Integer)
164
+ t = Time.now + arg
165
+ year, month, day, hour, minute, second = t.year, t.month, t.day, t.hour, t.min, t.sec
163
166
  else # we'll just assume it's a list of y/m/h/d/m/s
164
167
  year = arg || 0
165
168
  month = args.shift || 1
@@ -75,6 +75,23 @@ class TestTimecop < Test::Unit::TestCase
75
75
  assert_not_equal DateTime.new(2008, 10, 10, 0, 0, 0), DateTime.now
76
76
  end
77
77
 
78
+ def test_freeze_with_integer_instance_works_as_expected
79
+ t = Time.local(2008, 10, 10, 10, 10, 10)
80
+ Timecop.freeze(t) do
81
+ assert_equal t, Time.now
82
+ assert_equal DateTime.new(2008, 10, 10, 10, 10, 10), DateTime.now
83
+ assert_equal Date.new(2008, 10, 10), Date.today
84
+ Timecop.freeze(10) do
85
+ assert_equal t + 10, Time.now
86
+ assert_equal Time.local(2008, 10, 10, 10, 10, 20), Time.now
87
+ assert_equal Date.new(2008, 10, 10), Date.today
88
+ end
89
+ end
90
+ assert_not_equal t, Time.now
91
+ assert_not_equal DateTime.new(2008, 10, 10, 10, 10, 10), DateTime.now
92
+ assert_not_equal Date.new(2008, 10, 10), Date.today
93
+ end
94
+
78
95
  def test_exception_thrown_in_freeze_block_properly_resets_time
79
96
  t = Time.local(2008, 10, 10, 10, 10, 10)
80
97
  begin
@@ -41,6 +41,21 @@ class TestTimecopInternals < Test::Unit::TestCase
41
41
  assert_equal s, ts
42
42
  end
43
43
 
44
+ # Due to the nature of this test (calling Time.now once in this test and
45
+ # once in #parse_travel_args), this test may fail when two subsequent calls
46
+ # to Time.now return a different second.
47
+ def test_parse_travel_args_with_integer
48
+ t = Time.now
49
+ y, m, d, h, min, s = t.year, t.month, t.day, t.hour, t.min, t.sec
50
+ ty, tm, td, th, tmin, ts = Timecop.instance().send(:parse_travel_args, 0)
51
+ assert_equal y, ty
52
+ assert_equal m, tm
53
+ assert_equal d, td
54
+ assert_equal h, th
55
+ assert_equal min, tmin
56
+ assert_equal s, ts
57
+ end
58
+
44
59
  def test_parse_travel_args_with_individual_arguments
45
60
  y, m, d, h, min, s = 2008, 10, 10, 10, 10, 10
46
61
  ty, tm, td, th, tmin, ts = Timecop.instance().send(:parse_travel_args, y, m, d, h, min, s)
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.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Trupiano
@@ -9,50 +9,40 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-24 00:00:00 -05:00
12
+ date: 2009-03-06 00:00:00 -05:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: hoe
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.8.2
24
- version:
25
- 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 write test time-dependent code.
14
+ dependencies: []
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.
26
17
  email: jtrupiano@gmail.com
27
18
  executables: []
28
19
 
29
20
  extensions: []
30
21
 
31
- extra_rdoc_files:
32
- - History.txt
33
- - Manifest.txt
34
- - README.txt
22
+ extra_rdoc_files: []
23
+
35
24
  files:
36
25
  - History.txt
37
26
  - Manifest.txt
38
- - README.txt
39
27
  - Rakefile
40
- - lib/timecop.rb
28
+ - README.textile
29
+ - VERSION.yml
30
+ - lib/timecop
41
31
  - lib/timecop/stack_item.rb
42
32
  - lib/timecop/time_extensions.rb
43
33
  - lib/timecop/timecop.rb
44
34
  - lib/timecop/version.rb
35
+ - lib/timecop.rb
45
36
  - test/run_tests.sh
46
37
  - test/test_timecop.rb
47
38
  - test/test_timecop_internals.rb
48
39
  - test/test_timecop_without_date.rb
49
- - timecop.gemspec
50
40
  has_rdoc: true
51
41
  homepage: http://github.com/jtrupiano/timecop
52
42
  post_install_message:
53
43
  rdoc_options:
54
- - --main
55
- - README.txt
44
+ - --inline-source
45
+ - --charset=UTF-8
56
46
  require_paths:
57
47
  - lib
58
48
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -73,8 +63,6 @@ rubyforge_project: johntrupiano
73
63
  rubygems_version: 1.3.1
74
64
  signing_key:
75
65
  specification_version: 2
76
- 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 write test time-dependent code.
77
- test_files:
78
- - test/test_timecop.rb
79
- - test/test_timecop_internals.rb
80
- - test/test_timecop_without_date.rb
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
+
@@ -1,35 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{timecop}
5
- s.version = "0.2.0"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["John Trupiano"]
9
- s.date = %q{2008-12-23}
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 write test time-dependent code.}
11
- s.email = %q{jtrupiano@gmail.com}
12
- s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
13
- s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "lib/timecop.rb", "lib/timecop/stack_item.rb", "lib/timecop/time_extensions.rb", "lib/timecop/timecop.rb", "lib/timecop/version.rb", "test/run_tests.sh", "test/test_timecop.rb", "test/test_timecop_internals.rb", "test/test_timecop_without_date.rb", "timecop.gemspec"]
14
- s.has_rdoc = true
15
- s.homepage = %q{http://github.com/jtrupiano/timecop}
16
- s.rdoc_options = ["--main", "README.txt"]
17
- s.require_paths = ["lib"]
18
- s.rubyforge_project = %q{johntrupiano}
19
- s.rubygems_version = %q{1.3.1}
20
- s.summary = %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 write test time-dependent code.}
21
- s.test_files = ["test/test_timecop.rb", "test/test_timecop_internals.rb", "test/test_timecop_without_date.rb"]
22
-
23
- if s.respond_to? :specification_version then
24
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 2
26
-
27
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- s.add_development_dependency(%q<hoe>, [">= 1.8.2"])
29
- else
30
- s.add_dependency(%q<hoe>, [">= 1.8.2"])
31
- end
32
- else
33
- s.add_dependency(%q<hoe>, [">= 1.8.2"])
34
- end
35
- end