whenever-test 1.0.0 → 1.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 +4 -4
- data/Gemfile +5 -5
- data/README.md +10 -11
- data/Rakefile +2 -2
- data/lib/whenever/test.rb +1 -1
- data/lib/whenever/test/dsl.rb +5 -5
- data/lib/whenever/test/schedule.rb +3 -3
- data/lib/whenever/test/strict_hash.rb +1 -1
- data/spec/fixtures/schedule.rb +1 -1
- data/spec/whenever/test/schedule_spec.rb +15 -1
- data/whenever-test.gemspec +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2346b3f9e18edead15842c3fb6da7ec281acd28
|
4
|
+
data.tar.gz: b8d9acb025487943dcc0a0443d53345c18c76229
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c9751ae19c4ab6d1e75ddb6ff0ac0c4736d0aca22ee7d74d5245ea50110aa3d17e1420e937ebbff44eae554a1bea07d5ab4558ed7ab85095c0f13073bd6127f
|
7
|
+
data.tar.gz: 05f20610d2e781685a21230466f492f4f94eb5e6262df4a82db568407b038f6fe1e241754cbfd286c12835556b0c225a73e9855652f38c3de89b64d773374c62
|
data/Gemfile
CHANGED
@@ -3,12 +3,12 @@ source 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development, :test do
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem
|
6
|
+
gem 'bundler'
|
7
|
+
gem 'rake'
|
8
|
+
gem 'pry-byebug'
|
9
9
|
end
|
10
10
|
|
11
11
|
group :test do
|
12
|
-
gem
|
13
|
-
gem
|
12
|
+
gem 'minitest'
|
13
|
+
gem 'mocha', require: false
|
14
14
|
end
|
data/README.md
CHANGED
@@ -10,9 +10,9 @@ A gem that adds test support to [Whenever](https://github.com/javan/whenever) ge
|
|
10
10
|
|
11
11
|
### Background
|
12
12
|
|
13
|
-
I've been part of many projects that used whenever
|
13
|
+
I've been part of many projects that used [Whenever](https://github.com/javan/whenever), but testing the `schedule.rb` file was always neglected.
|
14
14
|
|
15
|
-
Turns out your jobs defined in Whenever schedule might reference rake tasks that don't exist in runtime and not even have correct ruby syntax (in case or runner-type jobs).
|
15
|
+
Turns out your jobs defined in [Whenever](https://github.com/javan/whenever) schedule might reference rake tasks that don't exist in runtime and not even have correct ruby syntax (in case or runner-type jobs).
|
16
16
|
|
17
17
|
This gem adds a support class so you can write specs that asserts against definitions in the `schedule.rb` file. To make sure ruby statements referenced in runner-type jobs actually work, you can `instance_eval` them and write expectations on what should happen, and then you'll be sure cron jobs won't have runtime issues that are detected only in staging or production environments.
|
18
18
|
|
@@ -20,7 +20,8 @@ NOTE: *This gem is test-framework agnostic, so you can use with RSpec, MiniTest,
|
|
20
20
|
|
21
21
|
### Installation
|
22
22
|
|
23
|
-
|
23
|
+
Since it's available in [Rubygems](https://rubygems.org/gems/whenever-test), just add the following to Gemfile:
|
24
|
+
Add this line to your Gemfile:
|
24
25
|
|
25
26
|
```ruby
|
26
27
|
group :test do
|
@@ -28,8 +29,6 @@ group :test do
|
|
28
29
|
end
|
29
30
|
```
|
30
31
|
|
31
|
-
Available in RubyGems: https://rubygems.org/gems/whenever-test
|
32
|
-
|
33
32
|
### Usage
|
34
33
|
|
35
34
|
Suppose you have a schedule such as:
|
@@ -78,21 +77,21 @@ describe 'Whenever Schedule' do
|
|
78
77
|
schedule = Whenever::Test::Schedule.new(file: fixture)
|
79
78
|
|
80
79
|
assert_equal 'http://myapp.com/cron-alive', schedule.jobs[:curl].first[:task]
|
81
|
-
assert_equal 'curl :task', schedule.jobs[:
|
82
|
-
assert_equal [:minute], schedule.jobs[:
|
80
|
+
assert_equal 'curl :task', schedule.jobs[:curl].first[:command]
|
81
|
+
assert_equal [:minute], schedule.jobs[:curl].first[:every]
|
83
82
|
end
|
84
83
|
end
|
85
84
|
```
|
86
85
|
|
87
86
|
**Now the important part:** these specs guarantee that:
|
88
87
|
|
89
|
-
1. If `TimeoutOffers` constant is not defined or `TimeoutOffers.perform_async`
|
90
|
-
2. If Rake task `db_sync:import` doesn't exist,
|
91
|
-
3. You should have a custom task named `curl` to make sure that job will work
|
88
|
+
1. If `TimeoutOffers` constant is not defined or `TimeoutOffers.perform_async` method doesn't exist, the spec fails
|
89
|
+
2. If Rake task `db_sync:import` doesn't exist, the spec fails
|
90
|
+
3. You should have a custom task named `curl` to make sure that job will work, otherwise the spec fails
|
92
91
|
|
93
92
|
### How it works
|
94
93
|
|
95
|
-
This gem implements a class that has the same DSL interface as Whenever gem. It basically runs the `schedule.rb` file against
|
94
|
+
This gem implements a class that has the same DSL interface as Whenever gem. It basically runs the `schedule.rb` file against `Whenever::Test::DSLInterpreter` and stores all statements and parameters found so you can easily query them in your tests.
|
96
95
|
|
97
96
|
### Contributors
|
98
97
|
|
data/Rakefile
CHANGED
data/lib/whenever/test.rb
CHANGED
data/lib/whenever/test/dsl.rb
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
module Whenever::Test
|
2
2
|
class DSLInterpreter
|
3
|
-
def initialize(schedule_world
|
3
|
+
def initialize(schedule_world)
|
4
4
|
@_world = schedule_world
|
5
|
-
vars.each do |name, value|
|
6
|
-
instance_variable_set("@#{name}", value)
|
7
|
-
end
|
8
5
|
end
|
9
6
|
|
10
7
|
def job_type(job, command)
|
11
8
|
@_world.jobs[job] = []
|
12
|
-
define_singleton_method(job) do |task, *
|
9
|
+
define_singleton_method(job) do |task, *_args|
|
13
10
|
@_world.jobs[job] << StrictHash[task: task, every: @_current_every, command: command]
|
14
11
|
end
|
15
12
|
end
|
@@ -20,6 +17,9 @@ module Whenever::Test
|
|
20
17
|
end
|
21
18
|
|
22
19
|
def set(name, value)
|
20
|
+
instance_variable_set("@#{name}".to_sym, value)
|
21
|
+
self.class.send(:attr_reader, name.to_sym)
|
22
|
+
|
23
23
|
@_world.sets[name] = value
|
24
24
|
end
|
25
25
|
|
@@ -7,16 +7,16 @@ module Whenever::Test
|
|
7
7
|
self.envs = {}
|
8
8
|
self.sets = {}
|
9
9
|
|
10
|
-
dsl = DSLInterpreter.new(self
|
10
|
+
dsl = DSLInterpreter.new(self)
|
11
11
|
setup_whenever(dsl)
|
12
|
+
vars.each { |k,v| dsl.set(k, v) }
|
12
13
|
parse(dsl, file)
|
13
14
|
end
|
14
15
|
|
15
16
|
private
|
16
17
|
|
17
18
|
def setup_whenever(dsl)
|
18
|
-
|
19
|
-
dsl.instance_eval File.read(whenever_setup_file)
|
19
|
+
parse(dsl, File.join(Gem.loaded_specs['whenever'].full_gem_path, 'lib', 'whenever', 'setup.rb').to_s)
|
20
20
|
end
|
21
21
|
|
22
22
|
def parse(dsl, file)
|
data/spec/fixtures/schedule.rb
CHANGED
@@ -30,12 +30,26 @@ describe Whenever::Test::Schedule do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
it 'makes sure `set` statements are captured ' do
|
33
|
+
it 'makes sure `set` statements are captured from the schedule file ' do
|
34
34
|
schedule = Whenever::Test::Schedule.new(file: fixture)
|
35
35
|
|
36
36
|
assert_equal 'bundle exec rails runner', schedule.sets[:runner_command]
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'makes sure `set` statements are captured from the setup file ' do
|
40
|
+
schedule = Whenever::Test::Schedule.new(file: fixture)
|
41
|
+
|
42
|
+
assert schedule.sets[:path]
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'makes sure user-specified variables override those in the setup file ' do
|
46
|
+
schedule = Whenever::Test::Schedule.new(file: fixture)
|
47
|
+
assert_equal 'production', schedule.sets[:environment]
|
48
|
+
|
49
|
+
schedule = Whenever::Test::Schedule.new(file: fixture, vars: { environment: 'staging' })
|
50
|
+
assert_equal 'staging', schedule.sets[:environment]
|
51
|
+
end
|
52
|
+
|
39
53
|
it 'makes sure `env` statements are captured ' do
|
40
54
|
schedule = Whenever::Test::Schedule.new(file: fixture)
|
41
55
|
|
data/whenever-test.gemspec
CHANGED
@@ -4,11 +4,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'whenever-test'
|
7
|
-
spec.version = '1.0.
|
7
|
+
spec.version = '1.0.1'
|
8
8
|
spec.authors = ['Rafael Sales']
|
9
9
|
spec.email = ['rafaelcds@gmail.com']
|
10
|
-
spec.summary =
|
11
|
-
spec.description =
|
10
|
+
spec.summary = 'Test Whenever scheduled jobs'
|
11
|
+
spec.description = "Whenever gem doesn't provide test support, so whenever-test makes that possible"
|
12
12
|
spec.homepage = 'https://github.com/heartbits/whenever-test'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whenever-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Sales
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: whenever
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
69
|
rubyforge_project:
|
70
|
-
rubygems_version: 2.
|
70
|
+
rubygems_version: 2.5.1
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: Test Whenever scheduled jobs
|