whenever 1.1.3 → 1.1.4

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.
@@ -1,142 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe 'Executable' do
4
- describe 'bin/wheneverize' do
5
- describe 'ARGV is not empty' do
6
- describe 'file does not exist' do
7
- file = '/tmp/this_does_not_exist'
8
-
9
- it 'prints STDERR' do
10
- out, err = capture_subprocess_io do
11
- system('wheneverize', file)
12
- end
13
-
14
- assert_empty(out)
15
- assert_match(/`#{file}' does not exist./, err)
16
- end
17
- end
18
-
19
- describe 'file exists, but not a directory' do
20
- file = '/tmp/this_is_a_file.txt'
21
- before { FileUtils.touch(file) }
22
-
23
- it 'prints STDERR' do
24
- begin
25
- out, err = capture_subprocess_io do
26
- system('wheneverize', file)
27
- end
28
-
29
- assert_empty(out)
30
- assert_match(/`#{file}' is not a directory./, err)
31
- ensure
32
- FileUtils.rm(file)
33
- end
34
- end
35
- end
36
-
37
- describe 'file is a directory, but another param(s) are given as well' do
38
- file = '/tmp/this_is_a_directory'
39
- before { FileUtils.mkdir(file) }
40
-
41
- it 'prints STDERR' do
42
- begin
43
- out, err = capture_subprocess_io do
44
- system('wheneverize', file, 'another', 'parameters')
45
- end
46
-
47
- assert_empty(out)
48
- assert_match(/#{"Too many arguments; please specify only the " \
49
- "directory to wheneverize."}/, err)
50
- ensure
51
- FileUtils.rmdir(file)
52
- end
53
- end
54
- end
55
- end
56
-
57
- describe 'ARGV is empty' do
58
- dir = '.'
59
- file = 'config/schedule.rb'
60
- path = File.join(dir, file)
61
-
62
- describe 'config file already exists' do
63
- before do
64
- FileUtils.mkdir(File.dirname(path))
65
- FileUtils.touch(path)
66
- end
67
-
68
- it 'prints STDOUT and STDERR' do
69
- begin
70
- out, err = capture_subprocess_io do
71
- system('wheneverize')
72
- end
73
-
74
- assert_match(/\[done\] wheneverized!/, out)
75
- assert_match(/\[skip\] `#{path}' already exists/, err)
76
- ensure
77
- FileUtils.rm_rf(File.dirname(path))
78
- end
79
- end
80
- end
81
-
82
- describe 'config directory does not exist' do
83
- it 'prints STDOUT and STDERR' do
84
- begin
85
- out, err = capture_subprocess_io do
86
- system('wheneverize')
87
- end
88
-
89
- assert_match(/\[add\] creating `#{File.dirname(path)}'\n/, err)
90
- assert_match(/\[done\] wheneverized!/, out)
91
- ensure
92
- FileUtils.rm_rf(File.dirname(path))
93
- end
94
- end
95
- end
96
-
97
- describe 'config directory exists, but file does not' do
98
- before { FileUtils.mkdir(File.dirname(path)) }
99
-
100
- it 'writes config file and prints STDOUT' do
101
- begin
102
- out, err = capture_subprocess_io do
103
- system('wheneverize')
104
- end
105
-
106
- assert_empty(err)
107
- assert_match(
108
- /\[add\] writing `#{path}'\n\[done\] wheneverized!/,
109
- out
110
- )
111
-
112
- assert_match((<<-FILE
113
- # Use this file to easily define all of your cron jobs.
114
- #
115
- # It's helpful, but not entirely necessary to understand cron before proceeding.
116
- # http://en.wikipedia.org/wiki/Cron
117
-
118
- # Example:
119
- #
120
- # set :output, "/path/to/my/cron_log.log"
121
- #
122
- # every 2.hours do
123
- # command "/usr/bin/some_great_command"
124
- # runner "MyModel.some_method"
125
- # rake "some:great:rake:task"
126
- # end
127
- #
128
- # every 4.days do
129
- # runner "AnotherModel.prune_old_records"
130
- # end
131
-
132
- # Learn more: http://github.com/javan/whenever
133
- FILE
134
- ), IO.read(path))
135
- ensure
136
- FileUtils.rm_rf(File.dirname(path))
137
- end
138
- end
139
- end
140
- end
141
- end
142
- end
@@ -1,114 +0,0 @@
1
- require 'test_helper'
2
-
3
- class JobTest < Whenever::TestCase
4
- should "return the :at set when #at is called" do
5
- assert_equal 'foo', new_job(:at => 'foo').at
6
- end
7
-
8
- should "return the :roles set when #roles is called" do
9
- assert_equal ['foo', 'bar'], new_job(:roles => ['foo', 'bar']).roles
10
- end
11
-
12
- should "return whether it has a role from #has_role?" do
13
- assert new_job(:roles => 'foo').has_role?('foo')
14
- assert_equal false, new_job(:roles => 'bar').has_role?('foo')
15
- end
16
-
17
- should "substitute the :task when #output is called" do
18
- job = new_job(:template => ":task", :task => 'abc123')
19
- assert_equal 'abc123', job.output
20
- end
21
-
22
- should "substitute the :path when #output is called" do
23
- assert_equal 'foo', new_job(:template => ':path', :path => 'foo').output
24
- end
25
-
26
- should "substitute the :path with the default Whenever.path if none is provided when #output is called" do
27
- Whenever.expects(:path).returns('/my/path')
28
- assert_equal '/my/path', new_job(:template => ':path').output
29
- end
30
-
31
- should "not substitute parameters for which no value is set" do
32
- assert_equal 'Hello :world', new_job(:template => ':matching :world', :matching => 'Hello').output
33
- end
34
-
35
- should "escape the :path" do
36
- assert_equal '/my/spacey\ path', new_job(:template => ':path', :path => '/my/spacey path').output
37
- end
38
-
39
- should "escape percent signs" do
40
- job = new_job(
41
- :template => "before :foo after",
42
- :foo => "percent -> % <- percent"
43
- )
44
- assert_equal %q(before percent -> \% <- percent after), job.output
45
- end
46
-
47
- should "assume percent signs are not already escaped" do
48
- job = new_job(
49
- :template => "before :foo after",
50
- :foo => %q(percent preceded by a backslash -> \% <-)
51
- )
52
- assert_equal %q(before percent preceded by a backslash -> \\\% <- after), job.output
53
- end
54
-
55
- should "squish spaces and newlines" do
56
- job = new_job(
57
- :template => "before :foo after",
58
- :foo => "newline -> \n <- newline space -> <- space"
59
- )
60
-
61
- assert_equal "before newline -> <- newline space -> <- space after", job.output
62
- end
63
- end
64
-
65
-
66
- class JobWithQuotesTest < Whenever::TestCase
67
- should "output the :task if it's in single quotes" do
68
- job = new_job(:template => "':task'", :task => 'abc123')
69
- assert_equal %q('abc123'), job.output
70
- end
71
-
72
- should "output the :task if it's in double quotes" do
73
- job = new_job(:template => '":task"', :task => 'abc123')
74
- assert_equal %q("abc123"), job.output
75
- end
76
-
77
- should "output escaped single quotes in when it's wrapped in them" do
78
- job = new_job(
79
- :template => "before ':foo' after",
80
- :foo => "quote -> ' <- quote"
81
- )
82
- assert_equal %q(before 'quote -> '\'' <- quote' after), job.output
83
- end
84
-
85
- should "output escaped double quotes when it's wrapped in them" do
86
- job = new_job(
87
- :template => 'before ":foo" after',
88
- :foo => 'quote -> " <- quote'
89
- )
90
- assert_equal %q(before "quote -> \" <- quote" after), job.output
91
- end
92
- end
93
-
94
- class JobWithJobTemplateTest < Whenever::TestCase
95
- should "use the job template" do
96
- job = new_job(:template => ':task', :task => 'abc123', :job_template => 'left :job right')
97
- assert_equal 'left abc123 right', job.output
98
- end
99
-
100
- should "reuse parameter in the job template" do
101
- job = new_job(:template => ':path :task', :path => 'path', :task => "abc123", :job_template => ':path left :job right')
102
- assert_equal 'path left path abc123 right', job.output
103
- end
104
-
105
- should "escape single quotes" do
106
- job = new_job(:template => "before ':task' after", :task => "quote -> ' <- quote", :job_template => "left ':job' right")
107
- assert_equal %q(left 'before '\''quote -> '\\''\\'\\'''\\'' <- quote'\'' after' right), job.output
108
- end
109
-
110
- should "escape double quotes" do
111
- job = new_job(:template => 'before ":task" after', :task => 'quote -> " <- quote', :job_template => 'left ":job" right')
112
- assert_equal %q(left "before \"quote -> \\\" <- quote\" after" right), job.output
113
- end
114
- end