Skip to content

Commit 3a54cf6

Browse files
committed
Initial commit
0 parents  commit 3a54cf6

File tree

10 files changed

+158
-0
lines changed

10 files changed

+158
-0
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
.yardoc
6+
Gemfile.lock
7+
InstalledFiles
8+
_yardoc
9+
coverage
10+
doc/
11+
lib/bundler/man
12+
pkg
13+
rdoc
14+
spec/reports
15+
test/tmp
16+
test/version_tmp
17+
tmp

.ruby-gemset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cucumber_timecop

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source "https://rubygems.org"
2+
3+
# Specify your gem's dependencies in cucumber-timecop.gemspec
4+
gemspec

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2013 zedtux
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.

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Cucumber Timecop gem
2+
3+
This gem install [timecop](https://github.com/travisjeffery/timecop) and [chronic](https://github.com/mojombo/chronic) gems and also include a cucumber step definition to use Timecop in you features.
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
gem 'cucumber-timecop'
10+
11+
And then execute:
12+
13+
$ bundle
14+
15+
Or install it yourself as:
16+
17+
$ gem install cucumber-timecop
18+
19+
## Usage
20+
21+
When this gem is installed, you can use the following cucumber steps:
22+
23+
Given it is currently 2 days ago
24+
Given time is frozen at midnight
25+
Given I jump in our Delorean and return to the present
26+
27+
## Contributing
28+
29+
1. Fork it
30+
2. Create your feature branch (`git checkout -b my-new-feature`)
31+
3. Commit your changes (`git commit -am 'Add some feature'`)
32+
4. Push to the branch (`git push origin my-new-feature`)
33+
5. Create new Pull Request

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require "bundler/gem_tasks"

cucumber-timecop.gemspec

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'cucumber/timecop/version'
5+
6+
Gem::Specification.new do |spec|
7+
spec.name = "cucumber-timecop"
8+
spec.version = Cucumber::Timecop::VERSION
9+
spec.authors = ["zedtux"]
10+
spec.email = ["zedtux@zedroot.org"]
11+
spec.description = %q{Timecop steps definition for Cucumber}
12+
spec.summary = %q{Add this gem to the test group of you Gemfile in order to be able to travel in time in you Cucumber scenarios.}
13+
spec.homepage = "https://github.com/zedtux/cucumber-timecop"
14+
spec.license = "MIT"
15+
16+
spec.files = `git ls-files`.split($/)
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_dependency "cucumber"
22+
spec.add_dependency "timecop"
23+
spec.add_dependency "chronic"
24+
25+
spec.add_development_dependency "bundler", "~> 1.3"
26+
spec.add_development_dependency "rake"
27+
28+
end

lib/cucumber/timecop.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require "chronic"
2+
require "timecop"
3+
4+
module TemporalHelpers
5+
6+
# Travels to +time+ and lets the clock keep running.
7+
#
8+
# If a block is given, executes the block at that
9+
# time then returns to the present.
10+
def travel_to(time, &block)
11+
Timecop.travel parse_time(time), &block
12+
end
13+
14+
# Travels to and freezes the clock at +time+.
15+
#
16+
# If a block is given, executes the block at that
17+
# time then returns to the present.
18+
def freeze_time_at(time, &block)
19+
Timecop.freeze parse_time(time), &block
20+
end
21+
22+
private
23+
24+
def parse_time(time)
25+
Chronic.parse(time) || Time.parse(time)
26+
end
27+
28+
end
29+
30+
World(TemporalHelpers)
31+
32+
Given /^it is currently (.+)$/ do |time|
33+
travel_to time
34+
end
35+
36+
Given /^time is frozen at (.+)$/ do |time|
37+
freeze_time_at time
38+
end
39+
40+
Given /^(?:I|we) jump in our Delorean and return to the present$/ do
41+
Timecop.return
42+
end
43+
44+
After do
45+
Timecop.return
46+
end

lib/cucumber/timecop/version.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Cucumber
2+
module Timecop
3+
VERSION = "0.0.1"
4+
end
5+
end

0 commit comments

Comments
 (0)