aughr-whenever 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class OutputCommandTest < Test::Unit::TestCase
4
+
5
+ context "A plain command" do
6
+ setup do
7
+ @output = Whenever.cron \
8
+ <<-file
9
+ every 2.hours do
10
+ command "blahblah"
11
+ end
12
+ file
13
+ end
14
+
15
+ should "output the command" do
16
+ assert_match /^.+ .+ .+ .+ blahblah$/, @output
17
+ end
18
+ end
19
+
20
+ context "A command when the cron_log is set" do
21
+ setup do
22
+ @output = Whenever.cron \
23
+ <<-file
24
+ set :cron_log, 'logfile.log'
25
+ every 2.hours do
26
+ command "blahblah"
27
+ end
28
+ file
29
+ end
30
+
31
+ should "output the command with the log syntax appended" do
32
+ assert_match /^.+ .+ .+ .+ blahblah >> logfile.log 2>&1$/, @output
33
+ end
34
+ end
35
+
36
+ context "A command when the cron_log is set and the comand overrides it" do
37
+ setup do
38
+ @output = Whenever.cron \
39
+ <<-file
40
+ set :cron_log, 'logfile.log'
41
+ every 2.hours do
42
+ command "blahblah", :cron_log => 'otherlog.log'
43
+ end
44
+ file
45
+ end
46
+
47
+ should "output the command with the log syntax appended" do
48
+ assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
49
+ assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1$/, @output
50
+ end
51
+ end
52
+
53
+ context "A command when the cron_log is set and the comand rejects it" do
54
+ setup do
55
+ @output = Whenever.cron \
56
+ <<-file
57
+ set :cron_log, 'logfile.log'
58
+ every 2.hours do
59
+ command "blahblah", :cron_log => false
60
+ end
61
+ file
62
+ end
63
+
64
+ should "output the command without the log syntax appended" do
65
+ assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
66
+ assert_match /^.+ .+ .+ .+ blahblah$/, @output
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class OutputEnvTest < Test::Unit::TestCase
4
+
5
+ context "The output from Whenever with environment variables set" do
6
+ setup do
7
+ @output = Whenever.cron \
8
+ <<-file
9
+ env :MYVAR, 'blah'
10
+ env 'MAILTO', "someone@example.com"
11
+ file
12
+ end
13
+
14
+ should "output MYVAR environment variable" do
15
+ assert_match "MYVAR=blah", @output
16
+ end
17
+
18
+ should "output MAILTO environment variable" do
19
+ assert_match "MAILTO=someone@example.com", @output
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,74 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class OutputRakeTest < Test::Unit::TestCase
4
+
5
+ # Rake are generated in an almost identical way to runners so we
6
+ # only need some basic tests to ensure they are output correctly
7
+
8
+ context "A rake command with path set" do
9
+ setup do
10
+ @output = Whenever.cron \
11
+ <<-file
12
+ set :path, '/my/path'
13
+ every 2.hours do
14
+ rake "blahblah"
15
+ end
16
+ file
17
+ end
18
+
19
+ should "output the rake command using that path" do
20
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production /usr/bin/env rake blahblah', @output
21
+ end
22
+ end
23
+
24
+ context "A rake command that overrides the path set" do
25
+ setup do
26
+ @output = Whenever.cron \
27
+ <<-file
28
+ set :path, '/my/path'
29
+ every 2.hours do
30
+ rake "blahblah", :path => '/some/other/path'
31
+ end
32
+ file
33
+ end
34
+
35
+ should "output the rake command using that path" do
36
+ assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production /usr/bin/env rake blahblah', @output
37
+ end
38
+ end
39
+
40
+ context "A rake command with environment set" do
41
+ setup do
42
+ @output = Whenever.cron \
43
+ <<-file
44
+ set :environment, :silly
45
+ set :path, '/my/path'
46
+ every 2.hours do
47
+ rake "blahblah"
48
+ end
49
+ file
50
+ end
51
+
52
+ should "output the rake command using that environment" do
53
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=silly /usr/bin/env rake blahblah', @output
54
+ end
55
+ end
56
+
57
+ context "A rake command that overrides the environment set" do
58
+ setup do
59
+ @output = Whenever.cron \
60
+ <<-file
61
+ set :environment, :silly
62
+ set :path, '/my/path'
63
+ every 2.hours do
64
+ rake "blahblah", :environment => :serious
65
+ end
66
+ file
67
+ end
68
+
69
+ should "output the rake command using that environment" do
70
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=serious /usr/bin/env rake blahblah', @output
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,125 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class OutputRunnerTest < Test::Unit::TestCase
4
+
5
+ context "A runner with path set" do
6
+ setup do
7
+ @output = Whenever.cron \
8
+ <<-file
9
+ set :path, '/my/path'
10
+ every 2.hours do
11
+ runner "blahblah"
12
+ end
13
+ file
14
+ end
15
+
16
+ should "output the runner using that path" do
17
+ assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
18
+ end
19
+ end
20
+
21
+ context "A runner that overrides the path set" do
22
+ setup do
23
+ @output = Whenever.cron \
24
+ <<-file
25
+ set :path, '/my/path'
26
+ every 2.hours do
27
+ runner "blahblah", :path => '/some/other/path'
28
+ end
29
+ file
30
+ end
31
+
32
+ should "output the runner using that path" do
33
+ assert_match two_hours + ' /some/other/path/script/runner -e production "blahblah"', @output
34
+ end
35
+ end
36
+
37
+ context "A runner with no path set and RAILS_ROOT defined" do
38
+ setup do
39
+ Whenever.stubs(:path).returns('/my/path')
40
+
41
+ @output = Whenever.cron \
42
+ <<-file
43
+ every 2.hours do
44
+ runner "blahblah"
45
+ end
46
+ file
47
+ end
48
+
49
+ should "output the runner using that path" do
50
+ assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
51
+ end
52
+ end
53
+
54
+ context "A runner with path set AND RAILS_ROOT defined" do
55
+ setup do
56
+ Whenever.stubs(:path).returns('/my/rails/path')
57
+
58
+ @output = Whenever.cron \
59
+ <<-file
60
+ set :path, '/my/path'
61
+ every 2.hours do
62
+ runner "blahblah"
63
+ end
64
+ file
65
+ end
66
+
67
+ should "use the path" do
68
+ assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
69
+ assert_no_match /\/rails\/path/, @output
70
+ end
71
+ end
72
+
73
+ context "A runner with no path set and no RAILS_ROOT defined" do
74
+ setup do
75
+ Whenever.stubs(:path).returns(nil)
76
+
77
+ @input = <<-file
78
+ every 2.hours do
79
+ runner "blahblah"
80
+ end
81
+ file
82
+ end
83
+
84
+ should "raise an exception" do
85
+ assert_raises ArgumentError do
86
+ Whenever.cron(@input)
87
+ end
88
+ end
89
+ end
90
+
91
+ context "A runner with an environment set" do
92
+ setup do
93
+ @output = Whenever.cron \
94
+ <<-file
95
+ set :environment, :silly
96
+ set :path, '/my/path'
97
+ every 2.hours do
98
+ runner "blahblah"
99
+ end
100
+ file
101
+ end
102
+
103
+ should "output the runner using that environment" do
104
+ assert_match two_hours + ' /my/path/script/runner -e silly "blahblah"', @output
105
+ end
106
+ end
107
+
108
+ context "A runner that overrides the environment set" do
109
+ setup do
110
+ @output = Whenever.cron \
111
+ <<-file
112
+ set :environment, :silly
113
+ set :path, '/my/path'
114
+ every 2.hours do
115
+ runner "blahblah", :environment => :serious
116
+ end
117
+ file
118
+ end
119
+
120
+ should "output the runner using that environment" do
121
+ assert_match two_hours + ' /my/path/script/runner -e serious "blahblah"', @output
122
+ end
123
+ end
124
+
125
+ end
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/whenever")
5
+
6
+ begin
7
+ require 'shoulda'
8
+ rescue LoadError
9
+ warn 'To test Whenever you need the shoulda gem:'
10
+ warn '$ sudo gem install thoughtbot-shoulda'
11
+ exit(1)
12
+ end
13
+
14
+ begin
15
+ require 'mocha'
16
+ rescue LoadError
17
+ warn 'To test Whenever you need the mocha gem:'
18
+ warn '$ sudo gem install mocha'
19
+ exit(1)
20
+ end
21
+
22
+
23
+ module TestExtensions
24
+
25
+ def two_hours
26
+ "0 0,2,4,6,8,10,12,14,16,18,20,22 * * *"
27
+ end
28
+
29
+ end
30
+
31
+ class Test::Unit::TestCase
32
+ include TestExtensions
33
+ end
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{whenever}
5
+ s.version = "0.2.3"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Javan Makhmali"]
9
+ s.date = %q{2009-06-02}
10
+ s.description = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.}
11
+ s.email = %q{javan@javan.us}
12
+ s.executables = ["whenever", "wheneverize"]
13
+ s.extra_rdoc_files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/command_line.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/version.rb", "lib/whenever.rb", "README.rdoc"]
14
+ s.files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/command_line.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/version.rb", "lib/whenever.rb", "Rakefile", "README.rdoc", "test/command_line_test.rb", "test/cron_test.rb", "test/output_command_test.rb", "test/output_env_test.rb", "test/output_rake_test.rb", "test/output_runner_test.rb", "test/test_helper.rb", "whenever.gemspec", "Manifest"]
15
+ s.has_rdoc = true
16
+ s.homepage = %q{http://github.com/javan/whenever}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whenever", "--main", "README.rdoc"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{whenever}
20
+ s.rubygems_version = %q{1.3.1}
21
+ s.summary = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.}
22
+ s.test_files = ["test/command_line_test.rb", "test/cron_test.rb", "test/output_command_test.rb", "test/output_env_test.rb", "test/output_rake_test.rb", "test/output_runner_test.rb", "test/test_helper.rb"]
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 2
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_runtime_dependency(%q<chronic>, [">= 0.2.3"])
30
+ s.add_runtime_dependency(%q<activesupport>, [">= 1.3.0"])
31
+ else
32
+ s.add_dependency(%q<chronic>, [">= 0.2.3"])
33
+ s.add_dependency(%q<activesupport>, [">= 1.3.0"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<chronic>, [">= 0.2.3"])
37
+ s.add_dependency(%q<activesupport>, [">= 1.3.0"])
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aughr-whenever
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
5
+ platform: ruby
6
+ authors:
7
+ - Javan Makhmali
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-02 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: chronic
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ version:
35
+ description: Provides clean ruby syntax for defining messy cron jobs and running them Whenever.
36
+ email: javan@javan.us
37
+ executables:
38
+ - whenever
39
+ - wheneverize
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - bin/whenever
44
+ - bin/wheneverize
45
+ - CHANGELOG.rdoc
46
+ - lib/base.rb
47
+ - lib/command_line.rb
48
+ - lib/job_list.rb
49
+ - lib/job_types/default.rb
50
+ - lib/job_types/rake_task.rb
51
+ - lib/job_types/runner.rb
52
+ - lib/outputs/cron.rb
53
+ - lib/version.rb
54
+ - lib/whenever.rb
55
+ - README.rdoc
56
+ files:
57
+ - bin/whenever
58
+ - bin/wheneverize
59
+ - CHANGELOG.rdoc
60
+ - lib/base.rb
61
+ - lib/command_line.rb
62
+ - lib/job_list.rb
63
+ - lib/job_types/default.rb
64
+ - lib/job_types/rake_task.rb
65
+ - lib/job_types/runner.rb
66
+ - lib/outputs/cron.rb
67
+ - lib/version.rb
68
+ - lib/whenever.rb
69
+ - Rakefile
70
+ - README.rdoc
71
+ - test/command_line_test.rb
72
+ - test/cron_test.rb
73
+ - test/output_command_test.rb
74
+ - test/output_env_test.rb
75
+ - test/output_rake_test.rb
76
+ - test/output_runner_test.rb
77
+ - test/test_helper.rb
78
+ - whenever.gemspec
79
+ - Manifest
80
+ has_rdoc: true
81
+ homepage: http://github.com/javan/whenever
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --line-numbers
85
+ - --inline-source
86
+ - --title
87
+ - Whenever
88
+ - --main
89
+ - README.rdoc
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "1.2"
103
+ version:
104
+ requirements: []
105
+
106
+ rubyforge_project: whenever
107
+ rubygems_version: 1.2.0
108
+ signing_key:
109
+ specification_version: 2
110
+ summary: Provides clean ruby syntax for defining messy cron jobs and running them Whenever.
111
+ test_files:
112
+ - test/command_line_test.rb
113
+ - test/cron_test.rb
114
+ - test/output_command_test.rb
115
+ - test/output_env_test.rb
116
+ - test/output_rake_test.rb
117
+ - test/output_runner_test.rb
118
+ - test/test_helper.rb