whenever 0.8.2 → 1.0.0
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 +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +20 -7
- data/Appraisals +19 -0
- data/CHANGELOG.md +116 -3
- data/Gemfile +3 -3
- data/LICENSE +2 -2
- data/README.md +133 -32
- data/Rakefile +3 -10
- data/bin/whenever +3 -0
- data/bin/wheneverize +8 -5
- data/gemfiles/activesupport4.1.gemfile +7 -0
- data/gemfiles/activesupport4.2.gemfile +7 -0
- data/gemfiles/activesupport5.0.gemfile +7 -0
- data/gemfiles/activesupport5.1.gemfile +7 -0
- data/gemfiles/activesupport5.2.gemfile +7 -0
- data/lib/whenever/capistrano/v2/hooks.rb +8 -0
- data/lib/whenever/capistrano/{recipes.rb → v2/recipes.rb} +7 -13
- data/lib/whenever/capistrano/{support.rb → v2/support.rb} +12 -0
- data/lib/whenever/capistrano/v3/tasks/whenever.rake +56 -0
- data/lib/whenever/capistrano.rb +5 -6
- data/lib/whenever/command_line.rb +69 -48
- data/lib/whenever/cron.rb +54 -25
- data/lib/whenever/job.rb +13 -14
- data/lib/whenever/job_list.rb +54 -24
- data/lib/whenever/numeric.rb +13 -0
- data/lib/whenever/numeric_seconds.rb +48 -0
- data/lib/whenever/os.rb +7 -0
- data/lib/whenever/output_redirection.rb +1 -0
- data/lib/whenever/setup.rb +19 -15
- data/lib/whenever/version.rb +2 -2
- data/lib/whenever.rb +19 -14
- data/test/functional/command_line_test.rb +379 -243
- data/test/functional/output_at_test.rb +227 -249
- data/test/functional/output_default_defined_jobs_test.rb +251 -193
- data/test/functional/output_defined_job_test.rb +65 -91
- data/test/functional/output_env_test.rb +22 -26
- data/test/functional/output_jobs_for_roles_test.rb +46 -65
- data/test/functional/output_jobs_with_mailto_test.rb +168 -0
- data/test/functional/output_redirection_test.rb +232 -291
- data/test/test_case.rb +32 -0
- data/test/test_helper.rb +44 -15
- data/test/unit/capistrano_support_test.rb +128 -134
- data/test/unit/cron_test.rb +373 -208
- data/test/unit/executable_test.rb +142 -0
- data/test/unit/job_test.rb +111 -117
- data/whenever.gemspec +7 -4
- metadata +63 -44
| @@ -1,307 +1,248 @@ | |
| 1 | 
            -
            require  | 
| 2 | 
            -
             | 
| 3 | 
            -
            class OutputRedirectionTest <  | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
                 | 
| 7 | 
            -
                   | 
| 8 | 
            -
                   | 
| 9 | 
            -
             | 
| 10 | 
            -
                     | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
                 | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 1 | 
            +
            require 'test_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class OutputRedirectionTest < Whenever::TestCase
         | 
| 4 | 
            +
              test "command when the output is set to nil" do
         | 
| 5 | 
            +
                output = Whenever.cron \
         | 
| 6 | 
            +
                <<-file
         | 
| 7 | 
            +
                  set :job_template, nil
         | 
| 8 | 
            +
                  set :output, nil
         | 
| 9 | 
            +
                  every 2.hours do
         | 
| 10 | 
            +
                    command "blahblah"
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                file
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> \/dev\/null 2>&1$/, output)
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
             | 
| 18 | 
            +
              test "command when the output is set" do
         | 
| 19 | 
            +
                output = Whenever.cron \
         | 
| 20 | 
            +
                <<-file
         | 
| 21 | 
            +
                  set :job_template, nil
         | 
| 22 | 
            +
                  set :output, 'logfile.log'
         | 
| 23 | 
            +
                  every 2.hours do
         | 
| 24 | 
            +
                    command "blahblah"
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                file
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> logfile.log 2>&1$/, output)
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              test "command when the error and standard output is set by the command" do
         | 
| 32 | 
            +
                output = Whenever.cron \
         | 
| 33 | 
            +
                <<-file
         | 
| 34 | 
            +
                  set :job_template, nil
         | 
| 35 | 
            +
                  every 2.hours do
         | 
| 36 | 
            +
                    command "blahblah", :output => {:standard => 'dev_null', :error => 'dev_err'}
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
                file
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output)
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              test "command when the output is set and the comand overrides it" do
         | 
| 44 | 
            +
                output = Whenever.cron \
         | 
| 45 | 
            +
                <<-file
         | 
| 46 | 
            +
                  set :job_template, nil
         | 
| 47 | 
            +
                  set :output, 'logfile.log'
         | 
| 48 | 
            +
                  every 2.hours do
         | 
| 49 | 
            +
                    command "blahblah", :output => 'otherlog.log'
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                file
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)
         | 
| 54 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1$/, output)
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              test "command when the output is set and the comand overrides with standard and error" do
         | 
| 58 | 
            +
                output = Whenever.cron \
         | 
| 59 | 
            +
                <<-file
         | 
| 60 | 
            +
                  set :job_template, nil
         | 
| 61 | 
            +
                  set :output, 'logfile.log'
         | 
| 62 | 
            +
                  every 2.hours do
         | 
| 63 | 
            +
                    command "blahblah", :output => {:error => 'dev_err', :standard => 'dev_null' }
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
                file
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)
         | 
| 68 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output)
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
              test "command when the output is set and the comand rejects it" do
         | 
| 72 | 
            +
                output = Whenever.cron \
         | 
| 73 | 
            +
                <<-file
         | 
| 74 | 
            +
                  set :job_template, nil
         | 
| 75 | 
            +
                  set :output, 'logfile.log'
         | 
| 76 | 
            +
                  every 2.hours do
         | 
| 77 | 
            +
                    command "blahblah", :output => false
         | 
| 78 | 
            +
                  end
         | 
| 79 | 
            +
                file
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)
         | 
| 82 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah$/, output)
         | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              test "command when the output is set and is overridden by the :set option" do
         | 
| 86 | 
            +
                output = Whenever.cron :set => 'output=otherlog.log', :string => \
         | 
| 87 | 
            +
                <<-file
         | 
| 88 | 
            +
                  set :job_template, nil
         | 
| 89 | 
            +
                  set :output, 'logfile.log'
         | 
| 90 | 
            +
                  every 2.hours do
         | 
| 91 | 
            +
                    command "blahblah"
         | 
| 92 | 
            +
                  end
         | 
| 93 | 
            +
                file
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)
         | 
| 96 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1/, output)
         | 
| 97 | 
            +
              end
         | 
| 98 | 
            +
             | 
| 99 | 
            +
              test "command when the error and standard output is set" do
         | 
| 100 | 
            +
                output = Whenever.cron \
         | 
| 101 | 
            +
                <<-file
         | 
| 102 | 
            +
                  set :job_template, nil
         | 
| 103 | 
            +
                  set :output, {:error => 'dev_err', :standard => 'dev_null' }
         | 
| 104 | 
            +
                  every 2.hours do
         | 
| 105 | 
            +
                    command "blahblah"
         | 
| 106 | 
            +
                  end
         | 
| 107 | 
            +
                file
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output)
         | 
| 110 | 
            +
              end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
              test "command when error output is set" do
         | 
| 113 | 
            +
                output = Whenever.cron \
         | 
| 114 | 
            +
                <<-file
         | 
| 115 | 
            +
                  set :job_template, nil
         | 
| 116 | 
            +
                  set :output, {:error => 'dev_null'}
         | 
| 117 | 
            +
                  every 2.hours do
         | 
| 118 | 
            +
                    command "blahblah"
         | 
| 119 | 
            +
                  end
         | 
| 120 | 
            +
                file
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah 2>> dev_null$/, output)
         | 
| 123 | 
            +
              end
         | 
| 124 | 
            +
             | 
| 125 | 
            +
              test "command when the standard output is set" do
         | 
| 126 | 
            +
                output = Whenever.cron \
         | 
| 127 | 
            +
                <<-file
         | 
| 128 | 
            +
                  set :job_template, nil
         | 
| 129 | 
            +
                  set :output, {:standard => 'dev_out'}
         | 
| 130 | 
            +
                  every 2.hours do
         | 
| 131 | 
            +
                    command "blahblah"
         | 
| 132 | 
            +
                  end
         | 
| 133 | 
            +
                file
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> dev_out$/, output)
         | 
| 136 | 
            +
              end
         | 
| 137 | 
            +
             | 
| 138 | 
            +
              test "command when error output is set by the command" do
         | 
| 139 | 
            +
                output = Whenever.cron \
         | 
| 140 | 
            +
                <<-file
         | 
| 141 | 
            +
                  set :job_template, nil
         | 
| 142 | 
            +
                  every 2.hours do
         | 
| 143 | 
            +
                    command "blahblah", :output => {:error => 'dev_err'}
         | 
| 144 | 
            +
                  end
         | 
| 145 | 
            +
                file
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah 2>> dev_err$/, output)
         | 
| 148 | 
            +
              end
         | 
| 149 | 
            +
             | 
| 150 | 
            +
              test "command when standard output is set by the command" do
         | 
| 151 | 
            +
                output = Whenever.cron \
         | 
| 152 | 
            +
                <<-file
         | 
| 153 | 
            +
                  set :job_template, nil
         | 
| 154 | 
            +
                  every 2.hours do
         | 
| 155 | 
            +
                    command "blahblah", :output => {:standard => 'dev_out'}
         | 
| 156 | 
            +
                  end
         | 
| 157 | 
            +
                file
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> dev_out$/, output)
         | 
| 160 | 
            +
              end
         | 
| 161 | 
            +
             | 
| 162 | 
            +
              test "command when standard output is set to nil" do
         | 
| 163 | 
            +
                output = Whenever.cron \
         | 
| 164 | 
            +
                <<-file
         | 
| 165 | 
            +
                  set :job_template, nil
         | 
| 166 | 
            +
                  every 2.hours do
         | 
| 167 | 
            +
                    command "blahblah", :output => {:standard => nil}
         | 
| 168 | 
            +
                  end
         | 
| 169 | 
            +
                file
         | 
| 170 | 
            +
             | 
| 171 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah > \/dev\/null$/, output)
         | 
| 172 | 
            +
              end
         | 
| 173 | 
            +
             | 
| 174 | 
            +
              test "command when standard error is set to nil" do
         | 
| 175 | 
            +
                output = Whenever.cron \
         | 
| 176 | 
            +
                <<-file
         | 
| 177 | 
            +
                  set :job_template, nil
         | 
| 178 | 
            +
                  every 2.hours do
         | 
| 179 | 
            +
                    command "blahblah", :output => {:error => nil}
         | 
| 180 | 
            +
                  end
         | 
| 181 | 
            +
                file
         | 
| 182 | 
            +
             | 
| 183 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah 2> \/dev\/null$/, output)
         | 
| 184 | 
            +
              end
         | 
| 185 | 
            +
             | 
| 186 | 
            +
              test "command when standard output and standard error is set to nil" do
         | 
| 187 | 
            +
                output = Whenever.cron \
         | 
| 188 | 
            +
                <<-file
         | 
| 189 | 
            +
                  set :job_template, nil
         | 
| 190 | 
            +
                  every 2.hours do
         | 
| 191 | 
            +
                    command "blahblah", :output => {:error => nil, :standard => nil}
         | 
| 192 | 
            +
                  end
         | 
| 193 | 
            +
                file
         | 
| 22 194 |  | 
| 23 | 
            -
             | 
| 24 | 
            -
                setup do
         | 
| 25 | 
            -
                  @output = Whenever.cron \
         | 
| 26 | 
            -
                  <<-file
         | 
| 27 | 
            -
                    set :job_template, nil
         | 
| 28 | 
            -
                    set :output, 'logfile.log'
         | 
| 29 | 
            -
                    every 2.hours do
         | 
| 30 | 
            -
                      command "blahblah"
         | 
| 31 | 
            -
                    end
         | 
| 32 | 
            -
                  file
         | 
| 33 | 
            -
                end
         | 
| 34 | 
            -
              
         | 
| 35 | 
            -
                should "output the command with the log syntax appended" do
         | 
| 36 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah >> logfile.log 2>&1$/, @output
         | 
| 37 | 
            -
                end
         | 
| 195 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah > \/dev\/null 2>&1$/, output)
         | 
| 38 196 | 
             
              end
         | 
| 39 197 |  | 
| 40 | 
            -
               | 
| 41 | 
            -
                 | 
| 42 | 
            -
             | 
| 43 | 
            -
                   | 
| 44 | 
            -
             | 
| 45 | 
            -
                     | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
                  file
         | 
| 49 | 
            -
                end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                should "output the command without the log syntax appended" do
         | 
| 52 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output
         | 
| 53 | 
            -
                end
         | 
| 54 | 
            -
              end
         | 
| 198 | 
            +
              test "command when standard output is set and standard error is set to nil" do
         | 
| 199 | 
            +
                output = Whenever.cron \
         | 
| 200 | 
            +
                <<-file
         | 
| 201 | 
            +
                  set :job_template, nil
         | 
| 202 | 
            +
                  every 2.hours do
         | 
| 203 | 
            +
                    command "blahblah", :output => {:error => nil, :standard => 'my.log'}
         | 
| 204 | 
            +
                  end
         | 
| 205 | 
            +
                file
         | 
| 55 206 |  | 
| 56 | 
            -
             | 
| 57 | 
            -
                setup do
         | 
| 58 | 
            -
                  @output = Whenever.cron \
         | 
| 59 | 
            -
                  <<-file
         | 
| 60 | 
            -
                    set :job_template, nil
         | 
| 61 | 
            -
                    set :output, 'logfile.log'
         | 
| 62 | 
            -
                    every 2.hours do
         | 
| 63 | 
            -
                      command "blahblah", :output => 'otherlog.log'
         | 
| 64 | 
            -
                    end
         | 
| 65 | 
            -
                  file
         | 
| 66 | 
            -
                end
         | 
| 67 | 
            -
              
         | 
| 68 | 
            -
                should "output the command with the command syntax appended" do
         | 
| 69 | 
            -
                  assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
         | 
| 70 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1$/, @output
         | 
| 71 | 
            -
                end
         | 
| 207 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> my.log 2> \/dev\/null$/, output)
         | 
| 72 208 | 
             
              end
         | 
| 73 209 |  | 
| 74 | 
            -
               | 
| 75 | 
            -
                 | 
| 76 | 
            -
             | 
| 77 | 
            -
                   | 
| 78 | 
            -
             | 
| 79 | 
            -
                     | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
                    end
         | 
| 83 | 
            -
                  file
         | 
| 84 | 
            -
                end
         | 
| 85 | 
            -
              
         | 
| 86 | 
            -
                should "output the command with the overridden redirection syntax appended" do
         | 
| 87 | 
            -
                  assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
         | 
| 88 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output
         | 
| 89 | 
            -
                end
         | 
| 90 | 
            -
              end
         | 
| 210 | 
            +
              test "command when standard output is nil and standard error is set" do
         | 
| 211 | 
            +
                output = Whenever.cron \
         | 
| 212 | 
            +
                <<-file
         | 
| 213 | 
            +
                  set :job_template, nil
         | 
| 214 | 
            +
                  every 2.hours do
         | 
| 215 | 
            +
                    command "blahblah", :output => {:error => 'my_error.log', :standard => nil}
         | 
| 216 | 
            +
                  end
         | 
| 217 | 
            +
                file
         | 
| 91 218 |  | 
| 92 | 
            -
             | 
| 93 | 
            -
                setup do
         | 
| 94 | 
            -
                  @output = Whenever.cron \
         | 
| 95 | 
            -
                  <<-file
         | 
| 96 | 
            -
                    set :job_template, nil
         | 
| 97 | 
            -
                    set :output, 'logfile.log'
         | 
| 98 | 
            -
                    every 2.hours do
         | 
| 99 | 
            -
                      command "blahblah", :output => false
         | 
| 100 | 
            -
                    end
         | 
| 101 | 
            -
                  file
         | 
| 102 | 
            -
                end
         | 
| 103 | 
            -
             | 
| 104 | 
            -
                should "output the command without the log syntax appended" do
         | 
| 105 | 
            -
                  assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
         | 
| 106 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah$/, @output
         | 
| 107 | 
            -
                end
         | 
| 219 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> \/dev\/null 2>> my_error.log$/, output)
         | 
| 108 220 | 
             
              end
         | 
| 109 221 |  | 
| 110 | 
            -
               | 
| 111 | 
            -
                 | 
| 112 | 
            -
             | 
| 113 | 
            -
                   | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 116 | 
            -
                     | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
                  file
         | 
| 120 | 
            -
                end
         | 
| 121 | 
            -
             | 
| 122 | 
            -
                should "output the otherlog.log as the log file" do
         | 
| 123 | 
            -
                  assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
         | 
| 124 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1/, @output
         | 
| 125 | 
            -
                end
         | 
| 126 | 
            -
              end
         | 
| 222 | 
            +
              test "command when the deprecated :cron_log is set" do
         | 
| 223 | 
            +
                output = Whenever.cron \
         | 
| 224 | 
            +
                <<-file
         | 
| 225 | 
            +
                  set :job_template, nil
         | 
| 226 | 
            +
                  set :cron_log, "cron.log"
         | 
| 227 | 
            +
                  every 2.hours do
         | 
| 228 | 
            +
                    command "blahblah"
         | 
| 229 | 
            +
                  end
         | 
| 230 | 
            +
                file
         | 
| 127 231 |  | 
| 128 | 
            -
             | 
| 129 | 
            -
                setup do
         | 
| 130 | 
            -
                  @output = Whenever.cron \
         | 
| 131 | 
            -
                  <<-file
         | 
| 132 | 
            -
                    set :job_template, nil
         | 
| 133 | 
            -
                    set :output, {:error => 'dev_err', :standard => 'dev_null' }
         | 
| 134 | 
            -
                    every 2.hours do
         | 
| 135 | 
            -
                      command "blahblah"
         | 
| 136 | 
            -
                    end
         | 
| 137 | 
            -
                  file
         | 
| 138 | 
            -
                end
         | 
| 139 | 
            -
             | 
| 140 | 
            -
                should "output the command without the redirection syntax appended" do
         | 
| 141 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output
         | 
| 142 | 
            -
                end
         | 
| 232 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah >> cron.log 2>&1$/, output)
         | 
| 143 233 | 
             
              end
         | 
| 144 234 |  | 
| 145 | 
            -
              context "A command when error output is set" do
         | 
| 146 | 
            -
                setup do
         | 
| 147 | 
            -
                  @output = Whenever.cron \
         | 
| 148 | 
            -
                  <<-file
         | 
| 149 | 
            -
                    set :job_template, nil
         | 
| 150 | 
            -
                    set :output, {:error => 'dev_null'}
         | 
| 151 | 
            -
                    every 2.hours do
         | 
| 152 | 
            -
                      command "blahblah"
         | 
| 153 | 
            -
                    end
         | 
| 154 | 
            -
                  file
         | 
| 155 | 
            -
                end
         | 
| 156 | 
            -
             | 
| 157 | 
            -
                should "output the command without the standard error syntax appended" do
         | 
| 158 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah 2>> dev_null$/, @output
         | 
| 159 | 
            -
                end
         | 
| 160 | 
            -
              end
         | 
| 161 235 |  | 
| 162 | 
            -
               | 
| 163 | 
            -
                 | 
| 164 | 
            -
             | 
| 165 | 
            -
                   | 
| 166 | 
            -
             | 
| 167 | 
            -
             | 
| 168 | 
            -
                     | 
| 169 | 
            -
             | 
| 170 | 
            -
             | 
| 171 | 
            -
                  file
         | 
| 172 | 
            -
                end
         | 
| 173 | 
            -
             | 
| 174 | 
            -
                should "output the command with standard output syntax appended" do
         | 
| 175 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah >> dev_out$/, @output
         | 
| 176 | 
            -
                end
         | 
| 177 | 
            -
              end
         | 
| 178 | 
            -
             | 
| 179 | 
            -
              context "A command when error output is set by the command" do
         | 
| 180 | 
            -
                setup do
         | 
| 181 | 
            -
                  @output = Whenever.cron \
         | 
| 182 | 
            -
                  <<-file
         | 
| 183 | 
            -
                    set :job_template, nil
         | 
| 184 | 
            -
                    every 2.hours do
         | 
| 185 | 
            -
                      command "blahblah", :output => {:error => 'dev_err'}
         | 
| 186 | 
            -
                    end
         | 
| 187 | 
            -
                  file
         | 
| 188 | 
            -
                end
         | 
| 189 | 
            -
             | 
| 190 | 
            -
                should "output the command without the log syntax appended" do
         | 
| 191 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah 2>> dev_err$/, @output
         | 
| 192 | 
            -
                end
         | 
| 193 | 
            -
              end
         | 
| 194 | 
            -
             | 
| 195 | 
            -
              context "A command when standard output is set by the command" do
         | 
| 196 | 
            -
                setup do
         | 
| 197 | 
            -
                  @output = Whenever.cron \
         | 
| 198 | 
            -
                  <<-file
         | 
| 199 | 
            -
                    set :job_template, nil
         | 
| 200 | 
            -
                    every 2.hours do
         | 
| 201 | 
            -
                      command "blahblah", :output => {:standard => 'dev_out'}
         | 
| 202 | 
            -
                    end
         | 
| 203 | 
            -
                  file
         | 
| 204 | 
            -
                end
         | 
| 205 | 
            -
             | 
| 206 | 
            -
                should "output the command without the log syntax appended" do
         | 
| 207 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah >> dev_out$/, @output
         | 
| 208 | 
            -
                end
         | 
| 209 | 
            -
              end
         | 
| 210 | 
            -
             | 
| 211 | 
            -
              context "A command when standard output is set to nil" do
         | 
| 212 | 
            -
                setup do
         | 
| 213 | 
            -
                  @output = Whenever.cron \
         | 
| 214 | 
            -
                  <<-file
         | 
| 215 | 
            -
                    set :job_template, nil
         | 
| 216 | 
            -
                    every 2.hours do
         | 
| 217 | 
            -
                      command "blahblah", :output => {:standard => nil}
         | 
| 218 | 
            -
                    end
         | 
| 219 | 
            -
                  file
         | 
| 220 | 
            -
                end
         | 
| 221 | 
            -
             | 
| 222 | 
            -
                should "output the command with stdout directed to /dev/null" do
         | 
| 223 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null$/, @output
         | 
| 224 | 
            -
                end
         | 
| 225 | 
            -
              end
         | 
| 226 | 
            -
             | 
| 227 | 
            -
              context "A command when standard error is set to nil" do
         | 
| 228 | 
            -
                setup do
         | 
| 229 | 
            -
                  @output = Whenever.cron \
         | 
| 230 | 
            -
                  <<-file
         | 
| 231 | 
            -
                    set :job_template, nil
         | 
| 232 | 
            -
                    every 2.hours do
         | 
| 233 | 
            -
                      command "blahblah", :output => {:error => nil}
         | 
| 234 | 
            -
                    end
         | 
| 235 | 
            -
                  file
         | 
| 236 | 
            -
                end
         | 
| 237 | 
            -
             | 
| 238 | 
            -
                should "output the command with stderr directed to /dev/null" do
         | 
| 239 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah 2> \/dev\/null$/, @output
         | 
| 240 | 
            -
                end
         | 
| 241 | 
            -
              end
         | 
| 242 | 
            -
             | 
| 243 | 
            -
              context "A command when standard output and standard error is set to nil" do
         | 
| 244 | 
            -
                setup do
         | 
| 245 | 
            -
                  @output = Whenever.cron \
         | 
| 246 | 
            -
                  <<-file
         | 
| 247 | 
            -
                    set :job_template, nil
         | 
| 248 | 
            -
                    every 2.hours do
         | 
| 249 | 
            -
                      command "blahblah", :output => {:error => nil, :standard => nil}
         | 
| 250 | 
            -
                    end
         | 
| 251 | 
            -
                  file
         | 
| 252 | 
            -
                end
         | 
| 253 | 
            -
             | 
| 254 | 
            -
                should "output the command with stderr directed to /dev/null" do
         | 
| 255 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null 2>&1$/, @output
         | 
| 256 | 
            -
                end
         | 
| 257 | 
            -
              end
         | 
| 258 | 
            -
             | 
| 259 | 
            -
              context "A command when standard output is set and standard error is set to nil" do
         | 
| 260 | 
            -
                setup do
         | 
| 261 | 
            -
                  @output = Whenever.cron \
         | 
| 262 | 
            -
                  <<-file
         | 
| 263 | 
            -
                    set :job_template, nil
         | 
| 264 | 
            -
                    every 2.hours do
         | 
| 265 | 
            -
                      command "blahblah", :output => {:error => nil, :standard => 'my.log'}
         | 
| 266 | 
            -
                    end
         | 
| 267 | 
            -
                  file
         | 
| 268 | 
            -
                end
         | 
| 269 | 
            -
             | 
| 270 | 
            -
                should "output the command with stderr directed to /dev/null" do
         | 
| 271 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah >> my.log 2> \/dev\/null$/, @output
         | 
| 272 | 
            -
                end
         | 
| 273 | 
            -
              end
         | 
| 274 | 
            -
             | 
| 275 | 
            -
              context "A command when standard output is nil and standard error is set" do
         | 
| 276 | 
            -
                setup do
         | 
| 277 | 
            -
                  @output = Whenever.cron \
         | 
| 278 | 
            -
                  <<-file
         | 
| 279 | 
            -
                    set :job_template, nil
         | 
| 280 | 
            -
                    every 2.hours do
         | 
| 281 | 
            -
                      command "blahblah", :output => {:error => 'my_error.log', :standard => nil}
         | 
| 282 | 
            -
                    end
         | 
| 283 | 
            -
                  file
         | 
| 284 | 
            -
                end
         | 
| 285 | 
            -
             | 
| 286 | 
            -
                should "output the command with stderr directed to /dev/null" do
         | 
| 287 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2>> my_error.log$/, @output
         | 
| 288 | 
            -
                end
         | 
| 289 | 
            -
              end
         | 
| 236 | 
            +
              test "a command when the standard output is set to a lambda" do
         | 
| 237 | 
            +
                output = Whenever.cron \
         | 
| 238 | 
            +
                <<-file
         | 
| 239 | 
            +
                  set :job_template, nil
         | 
| 240 | 
            +
                  set :output, lambda { "2>&1 | logger -t whenever_cron" }
         | 
| 241 | 
            +
                  every 2.hours do
         | 
| 242 | 
            +
                    command "blahblah"
         | 
| 243 | 
            +
                  end
         | 
| 244 | 
            +
                file
         | 
| 290 245 |  | 
| 291 | 
            -
             | 
| 292 | 
            -
                setup do
         | 
| 293 | 
            -
                  @output = Whenever.cron \
         | 
| 294 | 
            -
                  <<-file
         | 
| 295 | 
            -
                    set :job_template, nil
         | 
| 296 | 
            -
                    set :cron_log, "cron.log"
         | 
| 297 | 
            -
                    every 2.hours do
         | 
| 298 | 
            -
                      command "blahblah"
         | 
| 299 | 
            -
                    end
         | 
| 300 | 
            -
                  file
         | 
| 301 | 
            -
                end
         | 
| 302 | 
            -
             | 
| 303 | 
            -
                should "output the command with with the stdout and stderr going to the log" do
         | 
| 304 | 
            -
                  assert_match /^.+ .+ .+ .+ blahblah >> cron.log 2>&1$/, @output
         | 
| 305 | 
            -
                end
         | 
| 246 | 
            +
                assert_match(/^.+ .+ .+ .+ blahblah 2>&1 | logger -t whenever_cron$/, output)
         | 
| 306 247 | 
             
              end
         | 
| 307 248 | 
             
            end
         | 
    
        data/test/test_case.rb
    ADDED
    
    | @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            module Whenever
         | 
| 2 | 
            +
              require 'minitest/autorun'
         | 
| 3 | 
            +
              begin
         | 
| 4 | 
            +
                # 2.0.0
         | 
| 5 | 
            +
                class TestCase < MiniTest::Test; end
         | 
| 6 | 
            +
              rescue NameError
         | 
| 7 | 
            +
                # 1.9.3
         | 
| 8 | 
            +
                class TestCase < MiniTest::Unit::TestCase; end
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
             | 
| 12 | 
            +
              class TestCase
         | 
| 13 | 
            +
                class << self
         | 
| 14 | 
            +
                  def setup(&block)
         | 
| 15 | 
            +
                    define_method(:setup) do
         | 
| 16 | 
            +
                      super()
         | 
| 17 | 
            +
                      instance_eval(&block)
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  def test(name, &block)
         | 
| 22 | 
            +
                    define_method("test_#{name}".to_sym, &block)
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                  alias should test
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                def assert_no_match(regexp, string)
         | 
| 28 | 
            +
                  message = "<#{regexp}> expected to not match\n<#{string}>"
         | 
| 29 | 
            +
                  assert regexp !~ string, message
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
            end
         | 
    
        data/test/test_helper.rb
    CHANGED
    
    | @@ -1,18 +1,47 @@ | |
| 1 | 
            -
            # Want to test the files here, in lib, not in an installed version of the gem.
         | 
| 2 | 
            -
            $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
         | 
| 3 1 | 
             
            require 'whenever'
         | 
| 4 | 
            -
            require ' | 
| 5 | 
            -
            require ' | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
                 | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 2 | 
            +
            require 'test_case'
         | 
| 3 | 
            +
            require 'mocha/setup'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Whenever::TestHelpers
         | 
| 6 | 
            +
              protected
         | 
| 7 | 
            +
                def new_job(options={})
         | 
| 8 | 
            +
                  Whenever::Job.new(options)
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def parse_time(time = nil, task = nil, at = nil, options = {})
         | 
| 12 | 
            +
                  Whenever::Output::Cron.new(time, task, at, options).time_in_cron_syntax
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def two_hours
         | 
| 16 | 
            +
                  "0 0,2,4,6,8,10,12,14,16,18,20,22 * * *"
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def assert_months_and_days_and_hours_and_minutes_equals(expected, time, options = {})
         | 
| 20 | 
            +
                  cron = parse_time(Whenever.seconds(1, :year), 'some task', time, options)
         | 
| 21 | 
            +
                  minutes, hours, days, months = cron.split(' ')
         | 
| 22 | 
            +
                  assert_equal expected, [months, days, hours, minutes]
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def assert_days_and_hours_and_minutes_equals(expected, time, options = {})
         | 
| 26 | 
            +
                  cron = parse_time(Whenever.seconds(2, :months), 'some task', time, options)
         | 
| 27 | 
            +
                  minutes, hours, days, _ = cron.split(' ')
         | 
| 28 | 
            +
                  assert_equal expected, [days, hours, minutes]
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def assert_hours_and_minutes_equals(expected, time, options = {})
         | 
| 32 | 
            +
                  cron = parse_time(Whenever.seconds(2, :days), 'some task', time, options)
         | 
| 33 | 
            +
                  minutes, hours, _ = cron.split(' ')
         | 
| 34 | 
            +
                  assert_equal expected, [hours, minutes]
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def assert_minutes_equals(expected, time, options = {})
         | 
| 38 | 
            +
                  cron = parse_time(Whenever.seconds(2, :hours), 'some task', time, options)
         | 
| 39 | 
            +
                  assert_equal expected, cron.split(' ')[0]
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                def lines_without_empty_line(lines)
         | 
| 43 | 
            +
                  lines.map { |line| line.chomp }.reject { |line| line.empty? }
         | 
| 44 | 
            +
                end
         | 
| 14 45 | 
             
            end
         | 
| 15 46 |  | 
| 16 | 
            -
             | 
| 17 | 
            -
              include TestExtensions
         | 
| 18 | 
            -
            end
         | 
| 47 | 
            +
            Whenever::TestCase.send(:include, Whenever::TestHelpers)
         |