rspec-timecop 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rubocop.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +69 -0
- data/Rakefile +11 -0
- data/lib/rspec/timecop.rb +11 -0
- data/lib/rspec/timecop/helpers.rb +16 -0
- data/lib/rspec/timecop/version.rb +6 -0
- data/rspec-timecop.gemspec +27 -0
- data/spec/helper_spec.rb +11 -0
- metadata +140 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f99be0fbe3713aacacd1024a9e3db7e0b8bceaec
|
|
4
|
+
data.tar.gz: 0e6dbe58598683522dd6cd4ac9c85c4bb4f007b9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a2ce243560f1ca82d73ff74366fa509fe5c1c2727ac0829b964eb55210672328a2f224188eea5aa47643a0f22b17599b68cc66f6c9ac2aefb427f8eee6b124b9
|
|
7
|
+
data.tar.gz: 05a36d14d852785f0c76e0b3adbafd97c473b5f0e2cbbfb26f3bc229bdf6433d0558fb62400e4aecaf524b77709dc7b56dfa56b7cc28012f50164e713f974f02
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 SugarCRM Inc.
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
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
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Rspec::Timecop
|
|
2
|
+
|
|
3
|
+
RSpec extension for controlling time within examples.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'rspec-timecop'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install rspec-timecop
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
In a Rspec example you can use the timecopped method to freeze time for the
|
|
24
|
+
subject of the example:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
class Foobar
|
|
28
|
+
def self.hi
|
|
29
|
+
OtherObject.time_check(Time.now)
|
|
30
|
+
'hi'
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe Foobar do
|
|
35
|
+
let(:now) { Time.now }
|
|
36
|
+
before do
|
|
37
|
+
expect(OtherObject).to receive(:time_check)
|
|
38
|
+
.with(now)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe 'without the helper' do
|
|
42
|
+
subject do
|
|
43
|
+
result = nil
|
|
44
|
+
Timecop.freeze(now) { result = Foobar.hi }
|
|
45
|
+
result
|
|
46
|
+
end
|
|
47
|
+
it { should eq('hi') }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe 'with the helper' do
|
|
51
|
+
subject { timecopped(now) { Foobar.hi } }
|
|
52
|
+
it { should eq('hi') }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Without Timecop.freeze the value for Time.now being passed into ObjectOther#time_check could not be consistently checked.
|
|
58
|
+
And using #timecopped hides away example how Timecop.freeze is used so that we can see the subject call more clearly.
|
|
59
|
+
|
|
60
|
+
## Related
|
|
61
|
+
* https://github.com/travisjeffery/timecop/pull/119
|
|
62
|
+
|
|
63
|
+
## Contributing
|
|
64
|
+
|
|
65
|
+
1. Fork it ( https://github.com/[my-github-username]/rspec-timecop/fork )
|
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
67
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
68
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
69
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require 'bundler/gem_tasks'
|
|
3
|
+
require 'rspec/core/rake_task'
|
|
4
|
+
require 'rubocop/rake_task'
|
|
5
|
+
|
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
7
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
|
8
|
+
task.options = ['--out', 'tmp/rubocop.txt', '--format', 'progress']
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
task default: :spec
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
module Rspec
|
|
3
|
+
module Timecop
|
|
4
|
+
module Helpers
|
|
5
|
+
def timecopped(time)
|
|
6
|
+
result = nil
|
|
7
|
+
::Timecop.freeze(time) { result = yield }
|
|
8
|
+
result
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
RSpec.configure do |config|
|
|
15
|
+
config.include(Rspec::Timecop::Helpers)
|
|
16
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'rspec/timecop/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'rspec-timecop'
|
|
8
|
+
spec.version = Rspec::Timecop::VERSION
|
|
9
|
+
spec.authors = ['Andrew Sullivan Cant']
|
|
10
|
+
spec.email = ['acant@sugarcrm.com']
|
|
11
|
+
spec.summary = %q{RSpec extension to control time.}
|
|
12
|
+
spec.description = %q{Provides helper methods for using Timecop in RSpec examples.}
|
|
13
|
+
spec.homepage = 'http://github.com/sugarcrm/rspec-timecop'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ['lib']
|
|
20
|
+
|
|
21
|
+
spec.add_runtime_dependency 'rspec-core', '>= 2.99.0'
|
|
22
|
+
spec.add_runtime_dependency 'timecop', '~> 0.7.1'
|
|
23
|
+
spec.add_runtime_dependency 'rubocop', '~> 0.29.0'
|
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
26
|
+
spec.add_development_dependency 'rspec', '~> 2.99.0'
|
|
27
|
+
end
|
data/spec/helper_spec.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rspec-timecop
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andrew Sullivan Cant
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec-core
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 2.99.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 2.99.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: timecop
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.7.1
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ~>
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.7.1
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rubocop
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.29.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.29.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: bundler
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ~>
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.7'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ~>
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.7'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ~>
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '10.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ~>
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '10.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rspec
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ~>
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 2.99.0
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ~>
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 2.99.0
|
|
97
|
+
description: Provides helper methods for using Timecop in RSpec examples.
|
|
98
|
+
email:
|
|
99
|
+
- acant@sugarcrm.com
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- .gitignore
|
|
105
|
+
- .rubocop.yml
|
|
106
|
+
- Gemfile
|
|
107
|
+
- LICENSE.txt
|
|
108
|
+
- README.md
|
|
109
|
+
- Rakefile
|
|
110
|
+
- lib/rspec/timecop.rb
|
|
111
|
+
- lib/rspec/timecop/helpers.rb
|
|
112
|
+
- lib/rspec/timecop/version.rb
|
|
113
|
+
- rspec-timecop.gemspec
|
|
114
|
+
- spec/helper_spec.rb
|
|
115
|
+
homepage: http://github.com/sugarcrm/rspec-timecop
|
|
116
|
+
licenses:
|
|
117
|
+
- MIT
|
|
118
|
+
metadata: {}
|
|
119
|
+
post_install_message:
|
|
120
|
+
rdoc_options: []
|
|
121
|
+
require_paths:
|
|
122
|
+
- lib
|
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
|
+
requirements:
|
|
125
|
+
- - '>='
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: '0'
|
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
|
+
requirements:
|
|
130
|
+
- - '>='
|
|
131
|
+
- !ruby/object:Gem::Version
|
|
132
|
+
version: '0'
|
|
133
|
+
requirements: []
|
|
134
|
+
rubyforge_project:
|
|
135
|
+
rubygems_version: 2.0.14
|
|
136
|
+
signing_key:
|
|
137
|
+
specification_version: 4
|
|
138
|
+
summary: RSpec extension to control time.
|
|
139
|
+
test_files:
|
|
140
|
+
- spec/helper_spec.rb
|