timecop 0.5.9 → 0.6.0

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.
@@ -50,21 +50,21 @@ class Timecop
50
50
  @scaling_factor
51
51
  end
52
52
 
53
- def time(time_klass = Time) #:nodoc:
53
+ def time(klass = time_klass) #:nodoc:
54
54
  begin
55
- actual_time = time_klass.at(@time)
56
- calculated_time = time_klass.at(@time.to_f)
55
+ actual_time = klass.at(@time)
56
+ calculated_time = klass.at(@time.to_f)
57
57
  time = times_are_equal_within_epsilon(actual_time, calculated_time, 1) ? actual_time : calculated_time
58
58
  rescue
59
- time = time_klass.at(@time.to_f)
59
+ time = klass.at(@time.to_f)
60
60
  end
61
61
 
62
62
  if travel_offset.nil?
63
63
  time
64
64
  elsif scaling_factor.nil?
65
- time_klass.at(Time.now_without_mock_time + travel_offset)
65
+ klass.at(Time.now_without_mock_time + travel_offset)
66
66
  else
67
- time_klass.at(scaled_time)
67
+ klass.at(scaled_time)
68
68
  end
69
69
  end
70
70
 
@@ -103,7 +103,6 @@ class Timecop
103
103
  end
104
104
 
105
105
  def parse_time(*args)
106
- time_klass = Time.respond_to?(:zone) && Time.zone ? Time.zone : Time
107
106
  arg = args.shift
108
107
  if arg.is_a?(Time)
109
108
  if Timecop.active_support != false && arg.respond_to?(:in_time_zone)
@@ -151,5 +150,9 @@ class Timecop
151
150
  def times_are_equal_within_epsilon t1, t2, epsilon_in_seconds
152
151
  (t1 - t2).abs < epsilon_in_seconds
153
152
  end
153
+
154
+ def time_klass
155
+ Time.respond_to?(:zone) ? Time.zone : Time
156
+ end
154
157
  end
155
- end
158
+ end
@@ -107,7 +107,7 @@ class Timecop
107
107
  private
108
108
  def send_travel(mock_type, *args, &block)
109
109
  val = instance.send(:travel, mock_type, *args, &block)
110
- block_given? ? val : Time.now
110
+ block_given? ? val : Time.now
111
111
  end
112
112
  end
113
113
 
@@ -1,3 +1,3 @@
1
1
  class Timecop
2
- VERSION = "0.5.9"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -192,6 +192,16 @@ class TestTimeStackItem < Test::Unit::TestCase
192
192
  end
193
193
  end
194
194
 
195
+ def test_timezones_apply_dates
196
+ require 'active_support/all'
197
+ Time.zone = "Marshall Is."
198
+ time = Time.zone.local(2013,1,3)
199
+
200
+ Timecop.freeze(time) do
201
+ assert_equal time.to_date, Date.today
202
+ end
203
+ end
204
+
195
205
  def test_set_scaling_factor_for_scale
196
206
  t_now = Time.now
197
207
  t = Time.local(2009, 10, 1, 0, 0, 30)
@@ -247,7 +257,7 @@ class TestTimeStackItem < Test::Unit::TestCase
247
257
 
248
258
  def test_time_with_different_timezone
249
259
  require 'active_support/all'
250
-
260
+
251
261
  Time.zone = "Tokyo"
252
262
  t = Time.now
253
263
  Timecop.freeze(t) do
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timecop
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.5.9
4
+ version: 0.6.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Travis Jeffery
9
9
  - John Trupiano
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-09 00:00:00.000000000 Z
13
+ date: 2013-03-08 00:00:00.000000000 Z
14
14
  dependencies: []
15
- 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.
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.
16
18
  email: travisjeffery@gmail.com
17
19
  executables: []
18
20
  extensions: []
@@ -20,7 +22,6 @@ extra_rdoc_files:
20
22
  - LICENSE
21
23
  - README.markdown
22
24
  files:
23
- - History.rdoc
24
25
  - LICENSE
25
26
  - README.markdown
26
27
  - Rakefile
@@ -36,32 +37,33 @@ files:
36
37
  - test/timecop_without_date_test.rb
37
38
  - test/timecop_without_date_but_with_time_test.rb
38
39
  homepage: https://github.com/travisjeffery/timecop
39
- licenses: []
40
- post_install_message:
40
+ licenses:
41
+ - MIT
42
+ post_install_message:
41
43
  rdoc_options:
42
- - "--charset=UTF-8"
44
+ - --charset=UTF-8
43
45
  require_paths:
44
46
  - lib
45
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
46
49
  requirements:
47
- - - ">="
50
+ - - ! '>='
48
51
  - !ruby/object:Gem::Version
49
- version: !binary |-
50
- MA==
51
- none: false
52
+ version: '0'
52
53
  required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
53
55
  requirements:
54
- - - ">="
56
+ - - ! '>='
55
57
  - !ruby/object:Gem::Version
56
- version: !binary |-
57
- MA==
58
- none: false
58
+ version: '0'
59
59
  requirements: []
60
60
  rubyforge_project: timecop
61
- rubygems_version: 1.8.24
62
- signing_key:
61
+ rubygems_version: 1.8.23
62
+ signing_key:
63
63
  specification_version: 3
64
- 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.
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.
65
67
  test_files:
66
68
  - test/test_helper.rb
67
69
  - test/time_stack_item_test.rb
data/History.rdoc DELETED
@@ -1,142 +0,0 @@
1
- === 0.5.4 / 2012-11-29
2
-
3
- * Maintenance
4
- * Fix usage with Ruby 1.8
5
-
6
- === 0.5.2 / 2012-09-20
7
-
8
- * Feature
9
- * Timecop#scale, ability to accelerate time by a given scaling factor
10
-
11
- === 0.5.0 / 2012-09-12
12
-
13
- * Maintenance
14
- * Timecop#travel, Timecop#freeze blocks return nil or block value
15
-
16
- === 0.4.6 / 2012-09-05
17
-
18
- * Maintenance
19
- * Fix rounding support for Ruby < 1.9
20
-
21
- === 0.4.5 / 2012-08-09
22
-
23
- * Maintenance
24
- * Subclasses of Time/Date/DateTime now return proper instances
25
-
26
- === 0.4.4 / 2012-07-29
27
-
28
- * Maintenance
29
- * Can now configure Timecop to not use ActiveSupport by setting Timecop.active_support = false
30
-
31
- === 0.4.3 / 2012-07-27
32
-
33
- * Maintenance
34
- * Fix alias of Time#new/Time#now when Time#new given with args
35
-
36
- === 0.4.2 / 2012-07-27
37
-
38
- * Maintenance
39
- * Mock Time#new the same as Time#now since they're synonyms
40
- * Set default arg in parsing to 2000
41
- * Time.freeze defaults to Time#now
42
- * Use Time#parse is available to parse Time's given as strings
43
- * Add ActiveSupport Time.zone support
44
- * Stop DateTime from losing precision after traveling
45
-
46
- === 0.3.5 / 2010-06-07
47
-
48
- * Maintenance
49
- * Return a cloned time instance in order to support the destructive methods #gmt, #utc and #localtime
50
- * Don't use full path requires where unnecessary
51
-
52
- === 0.3.4 / 2009-12-07
53
-
54
- * Maintenance
55
- * Fix various timezone-related issues. Notably, when traveling to a DateTime
56
- instance specified in a non-local timezone, convert provided DateTime
57
- instance to a local instance and return that from DateTime.now.
58
- Code contributed by Michaël Witrant [piglop]
59
- * Fix bug that would not allow Timecop to be used when Ruby's 'date'
60
- library had not been previously loaded.
61
- Code contributed by Tuomas Kareinen [tuomas]
62
- * Fix bug when traveling to a DateTime across a DST boundary that
63
- resulted in DateTime's being off by an hour.
64
- * Migrate argument parsing into Timecop::TimeStackItem to reduce the
65
- responsibility of the Timecop class.
66
-
67
- === 0.3.3 2009-10-30
68
-
69
- * Revoked due to regression.
70
-
71
- === 0.3.2 / 2009-10-24
72
-
73
- * Revoked due to regression.
74
-
75
- === 0.3.1 / 2009-09-30
76
-
77
- * Maintenance
78
- * DRY up the Timecop class internals.
79
-
80
- === 0.3.0 / 2009-09-20
81
-
82
- * API
83
- * Completely remove Timecop#unset_all (deprecated by Timecop#return in 0.2.0)
84
- * Return Time.now from #freeze, #travel and #return -- code contributed by Keith Bennett [keithrbennett]
85
-
86
- * Maintenance
87
- * Fix bug that left Time#mock_time set in some instances
88
- * Upped build dependency to jeweler ~> 1.2.1
89
- * Don't pollute top-level namespace with classes/constants
90
-
91
- * Documentation
92
- * Clearer examples in the README, better description in the gemspec
93
- * Improve RDoc
94
-
95
- === 0.2.1 / 2009-03-06
96
- * API Changes
97
-
98
- * Introduced a 5th style of arguments to be passed into #travel and #freeze. Now, if you pass in a single integer value,
99
- it will be interpreted as a relative offset in seconds from the current Time.now. Previously this was interpreted as
100
- only the year, similar to calling Time.local(2008) --> Jan. 1, 2008. This is no longer the case.
101
-
102
- * Documentation
103
-
104
- * Moved to Textile for the README.
105
-
106
- * Added documentation for the new feature, and fixed a few typos.
107
-
108
- === 0.2.0 / 2008-12-23
109
-
110
- * API Changes
111
-
112
- * Timecop#travel no longer freezes time. Rather, it computes the current offset between the new "now" and the real "now", and
113
- returns times as if Time had continued to move forward
114
-
115
- * Timecop#freeze now behaves exactly as the old Timecop#travel behaved. Unless you depended on the actual freezing of time
116
- (which I think would be rare), you should be able to continue to use #travel without worry.
117
-
118
- * Timecop#return is now exposed (previously Timecop#unset_all, but not well advertised). It will completely unmock time,
119
- and will probably be rarely used outside of the actual implementation of this library.
120
-
121
- * More Test Coverage
122
-
123
- * Tests now explicitly cover the cases when the Date and DateTime objects are not loaded, and ensures proper functionality
124
- in their absence and existence.
125
-
126
- * Still haven't done regression testing against anything other than a few version of 1.8.6 (including REE). We should
127
- probably try to get this tested on both 1.8.7 and 1.9.1.
128
-
129
- * Documentation
130
-
131
- * Fixed up a lot of the poorly-formatted rdoc syntax. The public API should now be properly published in the rdoc,
132
- and the internals are omitted.
133
-
134
- === 0.1.0 / 2008-11-09
135
-
136
- * Initial Feature Set
137
-
138
- * Temporarily (or permanently if you prefer) change the concept of Time.now, DateTime.now (if defined), and Date.today (if defined)
139
- * Timecop#travel api allows an argument to be passed in as one of: 1) Time instance, 2) DateTime instance, 3) Date instance,
140
- 4) individual arguments (year, month, day, hour, minute, second)
141
- * Nested calls to Timecop#travel are supported -- each block will maintain it's interpretation of now.
142
-