whenever-test 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e58e9d99279233e6a8275a597c0027ad970833c
4
- data.tar.gz: 3e1c0a686c3c37d8ce9624fbed598330c6848840
3
+ metadata.gz: c2346b3f9e18edead15842c3fb6da7ec281acd28
4
+ data.tar.gz: b8d9acb025487943dcc0a0443d53345c18c76229
5
5
  SHA512:
6
- metadata.gz: ab551e5513e11c13624fe18334f5f26ef31b06546fcba4e39e4cfdffbf1ee41a27322af8c80bdd8f72fe5672134753d32d8c3eddc15d38dcb8921af707aedf53
7
- data.tar.gz: 8e6b25ec2930806c7073e8c4df9ddec90162d963ef2c98c853ccab87a5f95798f2b6927d7a8331b5370507ad68ce3d948b27d6a6f00766c94b3df64a6775ea18
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 "bundler"
7
- gem "rake"
8
- gem "pry-byebug"
6
+ gem 'bundler'
7
+ gem 'rake'
8
+ gem 'pry-byebug'
9
9
  end
10
10
 
11
11
  group :test do
12
- gem "minitest"
13
- gem "mocha", require: false
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 gem, but testing the `schedule.rb` file was always neglected.
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
- Add this line to your application's Gemfile:
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[:ping].first[:command]
82
- assert_equal [:minute], schedule.jobs[:ping].first[:every]
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` methods doesn't exist, an error will raise
90
- 2. If Rake task `db_sync:import` doesn't exist, an error will raise
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 the `Whenever::Test::DSLInterpreter` and stores all statements and parameters found so you can easily query them in your tests.
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
@@ -1,7 +1,7 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
- t.libs += ["spec", "lib"]
5
+ t.libs += %w(spec lib)
6
6
  t.test_files = FileList['spec/**/*_spec.rb']
7
7
  end
@@ -1,3 +1,3 @@
1
1
  require 'whenever'
2
2
 
3
- Dir.glob(File.join(File.dirname(__FILE__), "/test/**/*.rb")).sort.each { |f| require f }
3
+ Dir.glob(File.join(File.dirname(__FILE__), '/test/**/*.rb')).sort.each { |f| require f }
@@ -1,15 +1,12 @@
1
1
  module Whenever::Test
2
2
  class DSLInterpreter
3
- def initialize(schedule_world, vars)
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, *args|
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, vars)
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
- whenever_setup_file = File.join(Gem.loaded_specs['whenever'].full_gem_path, 'lib', 'whenever', 'setup.rb').to_s
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)
@@ -1,5 +1,5 @@
1
1
  module Whenever::Test
2
2
  class StrictHash < Hash
3
- alias [] fetch
3
+ alias_method :[], :fetch
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- set :output, '/var/log/whenever.log'
1
+ set :output, "#{path}/log/whenever.log"
2
2
  set :runner_command, 'bundle exec rails runner'
3
3
  job_type :ping, 'ping :task'
4
4
  env :PATH, ENV['PATH']
@@ -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
 
@@ -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.0'
7
+ spec.version = '1.0.1'
8
8
  spec.authors = ['Rafael Sales']
9
9
  spec.email = ['rafaelcds@gmail.com']
10
- spec.summary = %q{Test Whenever scheduled jobs}
11
- spec.description = %q{Whenever gem doesn't provide test support, so whenever-test makes that possible}
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.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: 2015-09-06 00:00:00.000000000 Z
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.4.5
70
+ rubygems_version: 2.5.1
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: Test Whenever scheduled jobs