timecop 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/timecop.rb CHANGED
@@ -1,2 +1,2 @@
1
- require 'timecop/timecop'
2
- require 'timecop/version'
1
+ require File.join(File.dirname(__FILE__), "timecop", "timecop")
2
+ require File.join(File.dirname(__FILE__), "timecop", "version")
@@ -1,6 +1,6 @@
1
1
  require 'singleton'
2
- require 'timecop/time_extensions'
3
- require 'timecop/time_stack_item'
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
- val = instance.send(:travel, :freeze, *args, &block)
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
- val = instance.send(:travel, :travel, *args, &block)
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
- val = instance.send(:travel, :scale, *args, &block)
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
@@ -1,3 +1,3 @@
1
1
  class Timecop
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'test/unit'
4
- require 'mocha'
4
+ begin
5
+ require 'mocha/setup'
6
+ rescue LoadError
7
+ require 'mocha'
8
+ end
5
9
 
6
10
  class Test::Unit::TestCase
7
11
 
@@ -1,5 +1,5 @@
1
1
  require 'date'
2
- require 'test_helper'
2
+ require File.join(File.dirname(__FILE__), "test_helper")
3
3
  require File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
4
4
 
5
5
  class TestTimeStackItem < Test::Unit::TestCase
data/test/timecop_test.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'date'
2
- require 'test_helper'
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
@@ -1,5 +1,5 @@
1
1
 
2
- require 'test_helper'
2
+ require File.join(File.dirname(__FILE__), "test_helper")
3
3
  require File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
4
4
 
5
5
  class TestTimecopWithoutDate < Test::Unit::TestCase
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
- prerelease: false
5
- segments:
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
- 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.
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
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- segments:
61
- - 0
62
- version: "0"
63
- required_rubygems_version: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- segments:
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.3.6
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 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.
77
- test_files:
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