[
  {
    "path": ".github/dependabot.yml",
    "content": "version: 2\nupdates:\n  - package-ecosystem: \"bundler\"\n    directory: \"/\"\n    schedule:\n      interval: \"monthly\"\n  - package-ecosystem: \"github-actions\"\n    directory: \"/\"\n    schedule:\n      interval: \"monthly\"\n"
  },
  {
    "path": ".github/workflows/ci.yml",
    "content": "name: Ruby CI\non:\n  pull_request:\n  push:\n    branches: [ main ]\npermissions:\n  contents: read\njobs:\n  test:\n    runs-on: ${{ matrix.os }}\n    strategy:\n      fail-fast: false\n      matrix:\n        os: [ubuntu-latest, macos-latest]\n        ruby-version: [ '2.4', '2.5', '2.6', '2.7', '3.0', '3.0', '3.2', '3.3', '3.4', '4.0', 'jruby-9', 'jruby-10']\n        # CRuby < 2.6 does not support macos-arm64, so test those on amd64 instead\n        exclude:\n          - os: macos-latest\n            ruby-version: '2.4'\n          - os: macos-latest\n            ruby-version: '2.5'\n        include:\n          - os: macos-15-intel\n            ruby-version: '2.4'\n          - os: macos-15-intel\n            ruby-version: '2.5'\n    steps:\n      - uses: actions/checkout@v6\n        name: Set up Ruby ${{ matrix.ruby-version }}\n      - uses: ruby/setup-ruby@v1\n        env:\n          JRUBY_OPTS: \"--debug\"\n        with:\n          ruby-version: ${{ matrix.ruby-version }}\n          bundler-cache: true # runs 'bundle install' and caches installed gems automatically\n      - name: Run tests\n        run: bundle exec rake test\n        env:\n          JRUBY_OPTS: \"--debug\"\n\n  # Test with activesupport\n  test-activesupport:\n    runs-on: ubuntu-latest\n    strategy:\n      fail-fast: false\n      matrix:\n        ruby-version: ['2.7', '3.0', '3.0', '3.2', '3.3', '3.4', '4.0']\n        rails-version: ['6.0', '6.1', '7.0', '7.1', '7.2', '8.0', '8.1']\n        include:\n          - ruby-version: 2.7\n            rails-version: '5.0'\n          - ruby-version: 2.7\n            rails-version: '5.1'\n          - ruby-version: 2.7\n            rails-version: '5.2'\n        exclude:\n          # rails 8.1: support ruby 3.2+\n          - ruby-version: 2.7\n            rails-version: '8.1'\n          - ruby-version: 3.0\n            rails-version: '8.1'\n          - ruby-version: 3.1\n            rails-version: '8.1'\n          # rails 8.0: support ruby 3.2+\n          - ruby-version: 2.7\n            rails-version: '8.0'\n          - ruby-version: 3.0\n            rails-version: '8.0'\n          - ruby-version: 3.1\n            rails-version: '8.0'\n          # rails 7.2: support ruby 3.1+\n          - ruby-version: 2.7\n            rails-version: '7.2'\n          - ruby-version: 3.0\n            rails-version: '7.2'\n    env:\n      BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/activesupport${{ matrix.rails-version }}.gemfile\n    steps:\n      - uses: actions/checkout@v6\n        name: Set up Ruby ${{ matrix.ruby-version }}\n      - uses: ruby/setup-ruby@v1\n        with:\n          ruby-version: ${{ matrix.ruby-version }}\n          bundler-cache: true\n      - name: Run tests\n        run: bundle exec rake test\n"
  },
  {
    "path": ".gitignore",
    "content": ".bundle/\n/.yardoc\n/_yardoc/\n/coverage/\n/doc/\n/pkg/\n/spec/reports/\ntmp/\n\n/Gemfile.lock\ngemfiles/*.lock\n.ruby-version\n\n.DS_Store\n.*.sw[a-z]\n"
  },
  {
    "path": "Appraisals",
    "content": "if RUBY_VERSION < \"3.0\"\n  appraise 'activesupport5.0' do\n    gem \"activesupport\", \"~> 5.0.0\"\n  end\n\n  appraise 'activesupport5.1' do\n    gem \"activesupport\", \"~> 5.1.0\"\n  end\n\n  appraise 'activesupport5.2' do\n    gem \"activesupport\", \"~> 5.2.0\"\n  end\nend\n\nappraise 'activesupport6.0' do\n  gem \"activesupport\", \"~> 6.0.0\"\n\n  # ruby 3.3+\n  gem \"base64\"\n  gem \"bigdecimal\"\n  gem \"mutex_m\"\n  # ruby 3.4+\n  gem \"benchmark\"\n  gem \"logger\"\n\n  # Fix https://github.com/rails/rails/issues/54260\n  gem 'concurrent-ruby', \"1.3.4\"\nend\n\nappraise 'activesupport6.1' do\n  gem \"activesupport\", \"~> 6.1.0\"\n\n  # ruby 3.3+\n  gem \"base64\"\n  gem \"bigdecimal\"\n  gem \"mutex_m\"\n  # ruby 3.4+\n  gem \"benchmark\"\n  gem \"logger\"\n\n  # Fix https://github.com/rails/rails/issues/54260\n  gem 'concurrent-ruby', \"1.3.4\"\nend\n\nif RUBY_VERSION >= \"2.7\"\n  appraise 'activesupport7.0' do\n    gem \"activesupport\", \"~> 7.0.0\"\n  end\nend\n\nif RUBY_VERSION >= \"3.1\"\n  appraise 'activesupport7.1' do\n    gem \"activesupport\", \"~> 7.1.0\"\n  end\nend\n\nif RUBY_VERSION >= \"3.2\"\n  appraise 'activesupport7.2' do\n    gem \"activesupport\", \"~> 7.2.0\"\n  end\n\n  appraise 'activesupport8.0' do\n    gem \"activesupport\", \"~> 8.0.0\"\n  end\n\n  appraise 'activesupport8.1' do\n    gem \"activesupport\", \"~> 8.1.0\"\n  end\nend\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "### unreleased\n\n\n### 1.1.2 / January 18, 2026\n\n* Add description as comment in crontab https://github.com/javan/whenever/pull/776\n\n* Override global option with group option https://github.com/javan/whenever/pull/822\n\n* CI: Add Ruby 4.0 to CI Matrix https://github.com/javan/whenever/pull/872\n\n* CI: Use macos-15-intel instead of macos-13 for Ruby 2.4 and 2.5 https://github.com/javan/whenever/pull/871\n\n### 1.1.1 / December 8, 2025\n\n* job_list `.respond_to?` updated to an instance method https://github.com/javan/whenever/pull/830\n\n* Update README.md https://github.com/javan/whenever/pull/789\n\n* CI: Bump actions/checkout from 5 to 6 https://github.com/javan/whenever/pull/869\n\n* CI: Add tests using ActiveSupport to CI https://github.com/javan/whenever/pull/868\n\n* Require MFA for gem releases https://github.com/javan/whenever/pull/867\n\n### 1.1.0 / November 21, 2025\n\n* Splat whenever_roles when passing to roles https://github.com/javan/whenever/pull/777\n\n* Update README.md https://github.com/javan/whenever/pull/785\n\n* Clarify in README that tasks are run in parallel https://github.com/javan/whenever/pull/787\n\n* Add note in README that cron is generated with the current user. [Raquel Queiroz] https://github.com/javan/whenever/pull/788\n\n* Clarify options and warn about overwriting https://github.com/javan/whenever/pull/791\n\n* Set the environment for cron jobs based off the currently set RAILS_ENV env variable. If RAILS_ENV is not set it defaults to production https://github.com/javan/whenever/pull/832\n\n* [CHORE] DX: easify getting started contributing https://github.com/javan/whenever/pull/846\n\n* CI: Replace travis-ci by Github-Actions https://github.com/javan/whenever/pull/847\n\n* Added capability for updating cron without cmd https://github.com/javan/whenever/pull/515\n\n* CI: Add Ruby 2.7-3.4 to the CI matrix https://github.com/javan/whenever/pull/858\n\n* CI: Add dependabot config for bundler / github-actions https://github.com/javan/whenever/pull/862\n\n* Handle crontab output to prevent SIGPIPE when running on CentOS Stream 10 https://github.com/javan/whenever/pull/861\n\n* CI: Bump actions/checkout from 4 to 5 https://github.com/javan/whenever/pull/863\n\n* Fix typo In test https://github.com/javan/whenever/pull/851\n\n* Add changelog_uri to metadata to easily link from rubygems.org https://github.com/javan/whenever/pull/786\n\n* Update gemspec format to match Bundler v3.x gemspec template https://github.com/javan/whenever/pull/864\n\n* Add to require `whenever/version` https://github.com/javan/whenever/pull/865\n\n### 1.0.0 / Jun 13, 2019\n\n* First stable release per SemVer.\n\n* Removes support for versions of Ruby which are no longer supported by the Ruby project.\n\n* Bugfix: Splat `whenever_roles` when passing to `roles` to allow definition of multiple whenever roles [samuelokrent](https://github.com/javan/whenever/pull/777)\n\n### 0.11.0 / April 23, 2019\n\n* Add support for mapping Range objects to cron range syntax [Tim Craft](https://github.com/javan/whenever/pull/725)\n\n* Bugfix: Avoid modifying Capistrano `default_env` when setting the whenever environment. [ta1kt0me](https://github.com/javan/whenever/pull/728)\n\n* Enable to execute whenever's task independently without setting :release_path or :whenever_path [ta1kt0me](https://github.com/javan/whenever/pull/729)\n\n* Make error message clearer when parsing cron syntax fails due to a trailing space [ignisf](https://github.com/javan/whenever/pull/744)\n\n### 0.10.0 / November 19, 2017\n\n* Modify wheneverize to allow for the creating of 'config' directory when not present\n\n* Add --crontab-command to whenever binary for overriding the crontab command. [Martin Grandrath]\n\n* Allow setting the path within which Capistrano will execute whenever. [Samuel Johnson](https://github.com/javan/whenever/pull/619)\n\n* Allow the use of string literals for month and day-of-week in raw cron syntax.. [Potamianos Gregory](https://github.com/javan/whenever/pull/711)\n\n* Include Capistrano default environment variables when executing Whenever. [Karl Li](https://github.com/javan/whenever/pull/719)\n\n* Allow configuring an alternative schedule file in Capistrano. [Shinichi Okamoto](https://github.com/javan/whenever/pull/666)\n\n* Add customizing email recipient option with the MAILTO environment variable. [Chikahiro Tokoro](https://github.com/javan/whenever/pull/678)\n\n### 0.9.7 / June 14, 2016\n\n* Restore compatibility with Capistrano v3; it has a bug which we have to work around [Ben Langfeld, Chris Gunther, Shohei Yamasaki]\n\n### 0.9.6 / June 13, 2016\n\n* Bypass symlinks when loading Capistrano v3 code, since these symlinks don't work in recent gem releases [Justin Ramos]\n\n### 0.9.5 / June 12, 2016\n\n* Improve documentation [Ben Langfeld, Spencer Fry]\n\n* Properly support Solaris / SmartOS [Steven Williamson]\n\n* Drop support for Ruby < 1.9.3. Test newer Ruby versions. [Javan Makhmali, Bartłomiej Kozal]\n\n* Suport Ruby 2.3.0 and Rails 4 [Vincent Boisard]\n\n* Set `RAILS_ENV` correctly in schedule when writing crontab from Capistrano [Ben Langfeld, Lorenzo Manacorda]\n\n* Minor refactoring, avoidance of Ruby warnings, etc [Ben Langfeld, DV Dasari]\n\n* Correctly pass through date expressions (e.g. `1.day`) inside job definitions [Rafael Sales]\n\n* Prevent writing invalid cron strings [Danny Fallon, Ben Langfeld]\n\n* Execute runner with `bundle exec` to ensure presence of app dependencies [Judith Roth]\n\n\n### 0.9.4 / October 24, 2014\n\n* Fix duplicated command line arguments when deploying to multiple servers with Cap 3. [betesh]\n\n* Set `whenever_environment` to the current stage before defaulting to production in Cap 3 tasks. [Karthik T]\n\n\n### 0.9.3 / October 5, 2014\n\n* Drop ActiveSupport dependency [James Healy, Javan Makhmali]\n\n* Drop shoulda for tests\n\n* Fix `whenever:clear_crontab` Cap 3 task [Javan Makhmali]\n\n* Avoid using tempfiles [ahoward]\n\n\n### 0.9.2 / March 4, 2014\n\n* Fix issues generating arguments for `execute` in Capistrano 3 tasks. [Javan Makhmali]\n\n\n### 0.9.1 / March 2, 2014\n\n* Pass `--roles` option to `whenever` in Capistrano 3 tasks. [betesh, Javan Makhmali]\n\n* Allow setting `:whenever_command` for Capistrano 3. [Javan Makhmali]\n\n* Allow `:whenever` command to be mapped in SSHKit. [Javan Makhmali]\n\n\n### 0.9.0 / December 17, 2013\n\n* Capistrano V3 support. [Philip Hallstrom]\n\n* Process params in job templates. [Austin Ziegler]\n\n\n### 0.8.4 / July 22, 2013\n\n* Don't require schedule file when clearing. [Javan Makhmali]\n\n* Use bin/rails when available. [Javan Makhmali]\n\n\n### 0.8.3 / July 11, 2013\n\n* Improve Cap rollback logic. [Jeroen Jacobs]\n\n* Allow configuration of the environment variable. [andfx]\n\n* Output option can be a callable Proc. [Li Xiao]\n\n\n### 0.8.2 / January 10, 2013\n\n* Fix Capistrano host options. [Igor Yamolov, Wes Morgan]\n\n* Improve JRuby test support. [Igor Yamolov]\n\n* Use correct release path in Cap task. [Wes Morgan]\n\n\n### 0.8.1 / December 22nd, 2012\n\n* Fix multiserver roles bug. [Wes Morgan]\n\n* Refactor Cap recipes and add tests for them. [Wes Morgan]\n\n* Fix file not found error when running under JRuby. [Wes Morgan]\n\n* Stop interpolating template attributes with no corresponding value. [Vincent Boisard]\n\n* Support for raw cron separated by tabs. [Étienne Barrié]\n\n\n### 0.8.0 / November 8th, 2012\n\n* Separate Capistrano recipes to allow custom execution. [Bogdan Gusiev]\n\n* Execute `whenever:update_crontab` before `deploy:finalize_update`, not `deploy:restart`. [Michal Wrobel]\n\n* Added a new `script` job type. [Ján Suchal]\n\n* Use correct path in Cap task. [Alex Dean]\n\n* Fix that setup.rb and schedule.rb were eval'd together. [Niklas H]\n\n* New Capistrano roles feature. [Wes Morgan]\n\n* Stop clearing the crontab during a deploy. [Javan Makhmali]\n\n* Bump Chronic gem dependency. [rainchen]\n\n\n### 0.7.3 / February 23rd, 2012\n\n* Make included Capistrano task compatible with both new and old versions of Cap. [Giacomo Macrì]\n\n\n### 0.7.2 / December 23rd, 2011\n\n* Accept @reboot and friends as raw cron syntax. [Felix Buenemann]\n\n* Fix clear_crontab task so it will work both standalone and during deploy. [Justin Giancola]\n\n\n### 0.7.1 / December 19th, 2011\n\n* Require thread before active_support for compatibility with Rails < 2.3.11 and RubyGems >= 1.6.0. [Micah Geisel]\n\n* More advanced role filtering in Cap task. [Brad Gessler]\n\n* Added whenever_variables as a configuration variable in Cap task. [Steve Agalloco]\n\n* Escape percent signs and reject newlines in jobs. [Amir Yalon]\n\n* Escape paths so spaces don't trip up cron. [Javan Makhmali]\n\n* Fix ambiguous handling of 1.month with :at. #99 [Javan Makhmali]\n\n\n### 0.7.0 / September 2nd, 2011\n\n* Use mojombo's chronic, it's active again. [Javan Makhmali]\n\n* Capistrano task enhancements. [Chris Griego]\n\n* wheneverize command defaults to '.' directory. [Andrew Nesbitt]\n\n* rake job_type uses bundler if detected. [Michał Szajbe]\n\n* Indicate filename in exceptions stemming from schedule file. [Javan Makhmali]\n\n* Don't require rubygems, bundler where possible. [Oleg Pudeyev]\n\n* Documentation and code cleanup. [many nice people]\n\n\n### 0.6.8 / May 24th, 2011\n\n* Convert most shortcuts to seconds. every :day -> every 1.day. #129 [Javan Makhmali]\n\n* Allow commas in raw cron syntax. #130 [Marco Bergantin, Javan Makhmali]\n\n* Output no update message as comments. #135 [Javan Makhmali]\n\n* require 'thread' to support Rubygems >= 1.6.0. #132 [Javan Makhmali]\n\n\n### 0.6.7 / March 23rd, 2011\n\n* Fix issue with comment block being corrupted during subsequent insertion of duplicate entries to the crontab. #123 [Jeremy (@lingmann)]\n\n* Removed -i from default job template. #118 [Javan Makhmali]\n\n\n### 0.6.6 / March 8th, 2011\n\n* Fix unclosed identifier bug. #119 [Javan Makhmali]\n\n\n### 0.6.5 / March 8th, 2011\n\n* Preserve whitespace at the end of crontab file. #95 [Rich Meyers]\n\n* Setting nil or blank environment variables now properly formats output. [T.J. VanSlyke]\n\n* Allow raw cron sytax, added -i to bash job template, general cleanup. [Javan Makhmali]\n\n\n### 0.6.2 / October 26th, 2010\n\n* --clear-crontab option completely removes entries. #63 [Javan Makhmali]\n\n* Set default :environment and :path earlier in the new setup.rb (formerly job_types/default.rb). [Javan Makhmali]\n\n* Converted README and CHANGELOG to markdown. [Javan Makhmali]\n\n\n### 0.6.1 / October 20th, 2010\n\n* Detect script/rails file and change runner to Rails 3 style if found. [Javan Makhmali]\n\n* Created a new :job_template system that can be applied to all commands. Wraps all in bash -l -c 'command..' by default now for better RVM support. Stopped automatically setting the PATH too. [Javan Makhmali]\n\n* Added a built-in Capistrano recipe. [Javan Makhmali]\n\n\n### 0.5.3 / September 24th, 2010\n\n* Better regexes for replacing Whenever blocks in the crontab. #45 [Javan Makhmali]\n\n* Preserving backslashes when updating existing crontab. #82 [Javan Makhmali]\n\n\n### 0.5.2 / September 15th, 2010\n\n* Quotes automatically escaped in jobs. [Jay Adkisson]\n\n* Added --cut option to the command line to allow pruning of the crontab. [Peer Allan]\n\n* Switched to aaronh-chronic which is ruby 1.9.2 compatible. [Aaron Hurley, Javan Makhmali]\n\n* Lots of internal reorganizing; tests broken into unit and functional. [Javan Makhmali]\n\n\n### 0.5.0 / June 28th, 2010\n\n* New job_type API for writing custom jobs. Internals use this to define command, runner, and rake. [Javan Makhmali - inspired by idlefingers (Damien)]\n\n* Jobs < 1.hour can specify an :at. [gorenje]\n\n* --clear option to remove crontab entries for a specific [identifier]. [mraidel (Michael Raidel)]\n\n\n### 0.4.2 / April 26th, 2010\n\n* runners now cd into the app's directory and then execute. [Michael Guterl]\n\n* Fix STDERR output redirection to file to append instead of overwrite. [weplay]\n\n* Move require of tempfile lib to file that actually uses it. [Finn Smith]\n\n* bugfix: comparison Time with 0 failed. #32 [Dan Hixon]\n\n\n### 0.4.1 / November 30th, 2009\n\n* exit(0) instead of just exit to make JRuby happy. [Elan Meng]\n\n* Fixed activesupport deprecation warning by requiring active_support. #37 [Andrew Nesbitt]\n\n\n### 0.4.0 / October 20th, 2009\n\n* New output option replaces the old cron_log option for output redirection and is much more flexible. #31 [Peer Allan]\n\n* Reorganized the lib files (http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices) and switched to Jeweler from Echoe.\n\n\n### 0.3.7 / September 4th, 2009\n\n* No longer tries (and fails) to combine @shortcut jobs. #20 [Javan Makhmali]\n\n\n### 0.3.6 / June 15th, 2009\n\n* Setting a PATH in the crontab automatically based on the user's PATH. [Javan Makhmali]\n\n\n### 0.3.5 / June 13th, 2009\n\n* Added ability to accept lists of every's and at's and intelligently group them. (ex: every 'monday, wednesday', :at => ['3pm', '6am']). [Sam Ruby]\n\n* Fixed issue with new lines. #18 [Javan Makhmali]\n\n### 0.3.1 / June 25th, 2009\n\n* Removed activesupport gem dependency. #1 [Javan Makhmali]\n\n* Switched to numeric days of the week for Solaris support (and probably others). #8 [Roger Ertesvåg]\n\n\n### 0.3.0 / June 2nd, 2009\n\n* Added ability to set variables on the fly from the command line (ex: whenever --set environment=staging). [Javan Makhmali]\n\n\n### 0.2.2 / April 30th, 2009\n\n* Days of week jobs can now accept an :at directive (ex: every :monday, :at => '5pm'). [David Eisinger]\n\n* Fixed command line test so it runs without a config/schedule.rb present. [Javan Makhmali]\n\n* Raising an exception if someone tries to specify an :at with a cron shortcut (:day, :reboot, etc) so there are no false hopes. [Javan Makhmali]\n\n\n### 0.1.7 / March 5th, 2009\n\n* Added ability to update the crontab file non-destuctively instead of only overwriting it. [Javan Makhmali -- Inspired by code submitted individually from: Tien Dung (tiendung), Tom Lea (cwninja), Kyle Maxwell (fizx), and Andrew Timberlake (andrewtimberlake) on github]\n\n\n### 0.1.5 / February 19th, 2009\n\n* Fixed load path so Whenever's files don't conflict with anything in Rails. Thanks Ryan Koopmans. [Javan Makhmali]\n\n\n### 0.1.4 / February 17th, 2009\n\n* Added --load-file and --user opts to whenever binary. [Javan Makhmali]\n\n\n### 0.1.3 / February 16th, 2009\n\n* Added 'rake' helper for defining scheduled rake tasks. [Javan Makhmali]\n\n* Renamed :cron_environment and :cron_path to :enviroment and :path for better (word) compatibility with rake tasks. [Javan Makhmali]\n\n* Improved test load paths so tests can be run individually. [Javan Makhmali]\n\n* Got rid of already initialized constant warning. [Javan Makhmali]\n\n* Requiring specific gem versions: Chronic >=0.2.3 and activesupport >= 1.3.0 [Javan Makhmali]\n\n\n### 0.1.0 / February 15th, 2009\n\n* Initial release [Javan Makhmali]\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "## How to contribute to Whenever\n\n#### **Did you find a bug?**\n\n* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/your/whenever/issues).\n\n* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/your/whenever/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.\n\n#### **Did you write a patch that fixes a bug?**\n\n* Open a new GitHub pull request with the patch.\n\n* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.\n\n\n#### **Do you have questions about the source code?**\n\n* Ask any question about how to use Whenever in the [whenever issues](https://github.com/javan/whenever/issues).\n\n#### **Do you want to contribute to the Whenever documentation?**\n\nWhenever is a volunteer effort. We encourage you to pitch in! \n\nThanks! :heart: :heart: :heart:\n\nWhenever Team\n\n---\n## Setup\n\n```bash\n$ bundle install\n```\n## Run tests\n\n```bash\n$ make test\n```\n"
  },
  {
    "path": "Gemfile",
    "content": "# frozen_string_literal: true\n\nsource \"https://rubygems.org\"\n\n# Specify your gem's dependencies in whenever.gemspec\ngemspec\n\ngem \"rake\"\ngem \"mocha\"\ngem \"minitest\"\ngem \"appraisal\"\n"
  },
  {
    "path": "LICENSE",
    "content": "Copyright (c) 2017 Javan Makhmali\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "Makefile",
    "content": ".DEFAULT_GOAL := test\n\ntest:\n\tbundle exec rake test\n.PHONY: test\n"
  },
  {
    "path": "README.md",
    "content": "Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.\n\n### Installation\n\n```sh\n$ gem install whenever\n```\n\nOr with Bundler in your Gemfile.\n\n```ruby\ngem 'whenever', require: false\n```\n\n### Getting started\n\n```sh\n$ cd /apps/my-great-project\n$ bundle exec wheneverize .\n```\n\nThis will create an initial `config/schedule.rb` file for you (as long as the config folder is already present in your project).\n\n### The `whenever` command\n\nThe `whenever` command will simply show you your `schedule.rb` file converted to cron syntax. It does not read or write your crontab file.\n\n```sh\n$ cd /apps/my-great-project\n$ bundle exec whenever\n```\n\nTo write your crontab file for your jobs, execute this command:\n\n```sh\n$ whenever --update-crontab\n```\n\nOther commonly used options include:\n```sh\n$ whenever --user app # set a user as which to install the crontab\n$ whenever --load-file config/my_schedule.rb # set the schedule file\n$ whenever --crontab-command 'sudo crontab' # override the crontab command\n```\n\n> Note: If you run the whenever --update-crontab without passing the --user attribute, cron will be generated by the current user. This mean tasks that needs other user permission will fail.\n\nYou can list installed cron jobs using `crontab -l`.\n\nRun `whenever --help` for a complete list of options for selecting the schedule to use, setting variables in the schedule, etc.\n\n### Example schedule.rb file\n\n```ruby\nevery 3.hours do # 1.minute 1.day 1.week 1.month 1.year is also supported\n  # the following tasks are run in parallel (not in sequence)\n  runner \"MyModel.some_process\"\n  rake \"my:rake:task\"\n  command \"/usr/bin/my_great_command\"\nend\n\nevery 1.day, at: '4:30 am' do\n  runner \"MyModel.task_to_run_at_four_thirty_in_the_morning\"\nend\n\nevery 1.day, at: ['4:30 am', '6:00 pm'] do\n  runner \"Mymodel.task_to_run_in_two_times_every_day\"\nend\n\nevery :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot\n  runner \"SomeModel.ladeeda\"\nend\n\nevery :sunday, at: '12pm' do # Use any day of the week or :weekend, :weekday\n  runner \"Task.do_something_great\"\nend\n\nevery '0 0 27-31 * *' do\n  command \"echo 'you can use raw cron syntax too'\"\nend\n\n# run this task only on servers with the :app role in Capistrano\n# see Capistrano roles section below\nevery :day, at: '12:20am', roles: [:app] do\n  rake \"app_server:task\"\nend\n```\n\n### Define your own job types\n\nWhenever ships with three pre-defined job types: command, runner, and rake. You can define your own with `job_type`.\n\nFor example:\n\n```ruby\njob_type :awesome, '/usr/local/bin/awesome :task :fun_level'\n\nevery 2.hours do\n  awesome \"party\", fun_level: \"extreme\"\nend\n```\n\nWould run `/usr/local/bin/awesome party extreme` every two hours. `:task` is always replaced with the first argument, and any additional `:whatevers` are replaced with the options passed in or by variables that have been defined with `set`.\n\nThe default job types that ship with Whenever are defined like so:\n\n```ruby\njob_type :command, \":task :output\"\njob_type :rake,    \"cd :path && :environment_variable=:environment :bundle_command rake :task --silent :output\"\njob_type :script,  \"cd :path && :environment_variable=:environment :bundle_command script/:task :output\"\njob_type :runner,  \"cd :path && :bundle_command :runner_command -e :environment ':task' :output\"\n```\n\nPre-Rails 3 apps and apps that don't use Bundler will redefine the `rake` and `runner` jobs respectively to function correctly.\n\nIf a `:path` is not set it will default to the directory in which `whenever` was executed. `:environment_variable` will default to 'RAILS_ENV'. `:environment` will default to 'production'. `:output` will be replaced with your output redirection settings which you can read more about here: <http://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs>\n\nAll jobs are by default run with `bash -l -c 'command...'`. Among other things, this allows your cron jobs to play nice with RVM by loading the entire environment instead of cron's somewhat limited environment. Read more: <http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production>\n\nYou can change this by setting your own `:job_template`.\n\n```ruby\nset :job_template, \"bash -l -c ':job'\"\n```\n\nOr set the job_template to nil to have your jobs execute normally.\n\n```ruby\nset :job_template, nil\n```\n\n### Parsing dates and times\n\nWhenever uses the [Chronic](https://github.com/mojombo/chronic) gem to parse the specified dates and times.\n\nYou can set your custom Chronic configuration if the defaults don't fit you.\n\nFor example, to assume a 24 hour clock instead of the default 12 hour clock:\n\n```ruby\nset :chronic_options, hours24: true\n\n# By default this would run the job every day at 3am\nevery 1.day, at: '3:00' do\n  runner \"MyModel.nightly_archive_job\"\nend\n```\n\nYou can see a list of all available options here: <https://github.com/mojombo/chronic/blob/master/lib/chronic/parser.rb>\n\n### Customize email recipient with the `MAILTO` environment variable\n\nOutput from the jobs is sent to the email address configured in the `MAILTO` environment variable.\n\nThere are many ways to further configure the recipient.\n\nExample: A global configuration, overriding the environment's value:\n\n```ruby\nenv 'MAILTO', 'output_of_cron@example.com'\n\nevery 3.hours do\n  command \"/usr/bin/my_great_command\"\nend\n```\n\nExample: A `MAILTO` configured for all the jobs in an interval block:\n\n```ruby\nevery 3.hours, mailto: 'my_super_command@example.com'  do\n  command \"/usr/bin/my_super_command\"\nend\n```\n\nExample: A `MAILTO` configured for a single job:\n\n```ruby\nevery 3.hours do\n  command \"/usr/bin/my_super_command\", mailto: 'my_super_command_output@example.com'\nend\n```\n\n### Adding comments to crontab\n\nA description can be added to a job that will be included in the crontab as a comment above the cron entry.\n\nExample: A single line description:\n\n```ruby\nevery 1.hours, description: \"My job description\" do\n  command \"/usr/bin/my_great_command\"\nend\n```\n\nExample: A multi line description:\n\n```ruby\nevery 1.hours, description: \"My job description\\nhas multiple lines\" do\n  command \"/usr/bin/my_great_command\"\nend\n```\n\n### Capistrano integration\n\nUse the built-in Capistrano recipe for easy crontab updates with deploys. For Capistrano V3, see the next section.\n\nIn your \"config/deploy.rb\" file:\n\n```ruby\nrequire \"whenever/capistrano\"\n```\n\nTake a look at the recipe for options you can set. <https://github.com/javan/whenever/blob/main/lib/whenever/capistrano/v2/recipes.rb>\nFor example, if you're using bundler do this:\n\n```ruby\nset :whenever_command, \"bundle exec whenever\"\nrequire \"whenever/capistrano\"\n```\n\nIf you are using different environments (such as staging, production), then you may want to do this:\n\n```ruby\nset :whenever_environment, defer { stage }\nrequire \"whenever/capistrano\"\n```\n\nThe capistrano variable `:stage` should be the one holding your environment name. This will make the correct `:environment` available in your `schedule.rb`.\n\nIf both your environments are on the same server you'll want to namespace them, or they'll overwrite each other when you deploy:\n\n```ruby\nset :whenever_environment, defer { stage }\nset :whenever_identifier, defer { \"#{application}_#{stage}\" }\nrequire \"whenever/capistrano\"\n```\n\nIf you use a schedule at an alternative path, you may configure it like so:\n\n```ruby\nset :whenever_load_file, defer { \"#{release_path}/somewhere/else/schedule.rb\" }\nrequire \"whenever/capistrano\"\n```\n\n### Capistrano V3 Integration\n\nIn your \"Capfile\" file:\n\n```ruby\nrequire \"whenever/capistrano\"\n```\n\nTake a look at the [load:defaults task](https://github.com/javan/whenever/blob/main/lib/whenever/capistrano/v3/tasks/whenever.rake) (bottom of file) for options you can set. For example, to namespace the crontab entries by application and stage do this in your \"config/deploy.rb\" file:\n\n```ruby\nset :whenever_identifier, ->{ \"#{fetch(:application)}_#{fetch(:stage)}\" }\n```\n\nThe Capistrano integration by default expects the `:application` variable to be set in order to scope jobs in the crontab.\n\n### Capistrano roles\n\nThe first thing to know about the new roles support is that it is entirely\noptional and backwards-compatible. If you don't need different jobs running on\ndifferent servers in your capistrano deployment, then you can safely stop reading\nnow and everything should just work the same way it always has.\n\nWhen you define a job in your schedule.rb file, by default it will be deployed to\nall servers in the whenever_roles list (which defaults to `[:db]`).\n\nHowever, if you want to restrict certain jobs to only run on subset of servers,\nyou can add a `roles: [...]` argument to their definitions. **Make sure to add\nthat role to the whenever_roles list in your deploy.rb.**\n\nWhen you run `cap deploy`, jobs with a :roles list specified will only be added to\nthe crontabs on servers with one or more of the roles in that list.\n\nJobs with no :roles argument will be deployed to all servers in the whenever_roles\nlist. This is to maintain backward compatibility with previous releases of whenever.\n\nSo, for example, with the default whenever_roles of `[:db]`, a job like this would be\ndeployed to all servers with the `:db` role:\n\n```ruby\nevery :day, at: '12:20am' do\n  rake 'foo:bar'\nend\n```\n\nIf we set whenever_roles to `[:db, :app]` in deploy.rb, and have the following\njobs in schedule.rb:\n\n```ruby\nevery :day, at: '1:37pm', roles: [:app] do\n  rake 'app:task' # will only be added to crontabs of :app servers\nend\n\nevery :hour, roles: [:db] do\n  rake 'db:task' # will only be added to crontabs of :db servers\nend\n\nevery :day, at: '12:02am' do\n  command \"run_this_everywhere\" # will be deployed to :db and :app servers\nend\n```\n\nHere are the basic rules:\n\n  1. If a server's role isn't listed in whenever_roles, it will *never* have jobs\n     added to its crontab.\n  1. If a server's role is listed in the whenever_roles, then it will have all\n     jobs added to its crontab that either list that role in their :roles arg or\n     that don't have a :roles arg.\n  1. If a job has a :roles arg but that role isn't in the whenever_roles list,\n     that job *will not* be deployed to any server.\n\n### RVM Integration\n\nIf your production environment uses RVM (Ruby Version Manager) you will run into a gotcha that causes your cron jobs to hang.  This is not directly related to Whenever, and can be tricky to debug.  Your .rvmrc files must be trusted or else the cron jobs will hang waiting for the file to be trusted.  A solution is to disable the prompt by adding this line to your user rvm file in `~/.rvmrc`\n\n`rvm_trust_rvmrcs_flag=1`\n\nThis tells rvm to trust all rvmrc files.\n\n### Heroku?\n\nNo. Heroku does not support cron, instead providing [Heroku Scheduler](https://devcenter.heroku.com/articles/scheduler). If you deploy to Heroku, you should use that rather than Whenever.\n\n### Testing\n\n[whenever-test](https://github.com/heartbits/whenever-test) is an extension to Whenever for testing a Whenever schedule.\n\n### Credit\n\nWhenever was created for use at Inkling (<http://inklingmarkets.com>). Their take on it: <http://blog.inklingmarkets.com/2009/02/whenever-easy-way-to-do-cron-jobs-from.html>\n\nThanks to all the contributors who have made it even better: <http://github.com/javan/whenever/contributors>\n\n### Discussion / Feedback / Issues / Bugs\n\nFor general discussion and questions, please use the google group: <http://groups.google.com/group/whenever-gem>\n\nIf you've found a genuine bug or issue, please use the Issues section on github: <http://github.com/javan/whenever/issues>\n\nRyan Bates created a great Railscast about Whenever: <http://railscasts.com/episodes/164-cron-in-ruby>\nIt's a little bit dated now, but remains a good introduction.\n\n----\n\nCopyright &copy; 2017 Javan Makhmali\n"
  },
  {
    "path": "Rakefile",
    "content": "require 'bundler/gem_tasks'\nrequire 'rake/testtask'\n\nRake::TestTask.new(:test) do |test|\n  test.libs      << 'lib' << 'test'\n  test.pattern   = 'test/{functional,unit}/**/*_test.rb'\n  test.verbose   = true\nend\n\ntask :default => :test\n"
  },
  {
    "path": "bin/whenever",
    "content": "#!/usr/bin/env ruby\n\nrequire 'optparse'\nrequire 'whenever'\n\noptions = {}\n\nOptionParser.new do |opts|\n  opts.banner = \"Usage: whenever [options]\"\n  opts.on('-i', '--update-crontab [schedule]',\n          'Install the schedule to crontab.',\n          '  Default: full path to schedule.rb file') do |identifier|\n    options[:update] = true\n    options[:identifier] = identifier if identifier\n  end\n  opts.on('-w', '--write-crontab [schedule]',\n          'Clear current crontab, and overwrite it with only the given schedule.',\n          '  Default: full path to schedule.rb file') do |identifier|\n     options[:write] = true\n     options[:identifier] = identifier if identifier\n  end\n  opts.on('-c', '--clear-crontab [schedule]',\n          'Uninstall the schedule from crontab.',\n          '  Default: full path to schedule.rb file') do |identifier|    \n    options[:clear] = true\n    options[:identifier] = identifier if identifier\n  end\n  opts.on('-s', '--set [variables]', 'Example: --set \\'environment=staging&path=/my/sweet/path\\'') do |set|\n    options[:set] = set if set\n  end\n  opts.on('-f', '--load-file [schedule file]', 'Default: config/schedule.rb') do |file|\n    options[:file] = file if file\n  end\n  opts.on('-u', '--user [user]', 'Default: current user') do |user|\n    options[:user] = user if user\n  end\n  opts.on('-k', '--cut [lines]', 'Cut lines from the top of the cronfile') do |lines|\n    options[:cut] = lines.to_i if lines\n  end\n  opts.on('-r', '--roles [role1,role2]', 'Comma-separated list of server roles to generate cron jobs for') do |roles|\n    options[:roles] = roles.split(',').map(&:to_sym) if roles\n  end\n  opts.on('-x', '--crontab-command [command]', 'Default: crontab') do |crontab_command|\n    options[:crontab_command] = crontab_command if crontab_command\n  end\n  opts.on('-v', '--version') { puts \"Whenever v#{Whenever::VERSION}\"; exit(0) }\nend.parse!\n\nWhenever::CommandLine.execute(options)\n"
  },
  {
    "path": "bin/wheneverize",
    "content": "#!/usr/bin/env ruby\n\n# This file is based heavily on Capistrano's `capify` command\n\nrequire 'optparse'\nrequire 'fileutils'\n\nOptionParser.new do |opts|\n  opts.banner = \"Usage: #{File.basename($0)} [path]\"\n\n  begin\n    opts.parse!(ARGV)\n  rescue OptionParser::ParseError => e\n    warn e.message\n    puts opts\n    exit 1\n  end\nend\n\nunless ARGV.empty?\n  if !File.exist?(ARGV.first)\n    abort \"`#{ARGV.first}' does not exist.\"\n  elsif !File.directory?(ARGV.first)\n    abort \"`#{ARGV.first}' is not a directory.\"\n  elsif ARGV.length > 1\n    abort \"Too many arguments; please specify only the directory to wheneverize.\"\n  end\nend\n\ncontent = <<-FILE\n# Use this file to easily define all of your cron jobs.\n#\n# It's helpful, but not entirely necessary to understand cron before proceeding.\n# http://en.wikipedia.org/wiki/Cron\n\n# Example:\n#\n# set :output, \"/path/to/my/cron_log.log\"\n#\n# every 2.hours do\n#   command \"/usr/bin/some_great_command\"\n#   runner \"MyModel.some_method\"\n#   rake \"some:great:rake:task\"\n# end\n#\n# every 4.days do\n#   runner \"AnotherModel.prune_old_records\"\n# end\n\n# Learn more: http://github.com/javan/whenever\nFILE\n\nfile = 'config/schedule.rb'\nbase = ARGV.empty? ? '.' : ARGV.shift\n\nfile = File.join(base, file)\nif File.exist?(file)\n  warn \"[skip] `#{file}' already exists\"\nelsif File.exist?(file.downcase)\n  warn \"[skip] `#{file.downcase}' exists, which could conflict with `#{file}'\"\nelse\n  dir = File.dirname(file)\n  if !File.exist?(dir)\n    warn \"[add] creating `#{dir}'\"\n    FileUtils.mkdir_p(dir)\n  end\n  puts \"[add] writing `#{file}'\"\n  File.open(file, \"w\") { |f| f.write(content) }\nend\n\nputs \"[done] wheneverized!\"\n"
  },
  {
    "path": "gemfiles/activesupport5.0.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"rake\"\ngem \"mocha\"\ngem \"minitest\"\ngem \"appraisal\"\ngem \"activesupport\", \"~> 5.0.0\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/activesupport5.1.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"rake\"\ngem \"mocha\"\ngem \"minitest\"\ngem \"appraisal\"\ngem \"activesupport\", \"~> 5.1.0\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/activesupport5.2.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"rake\"\ngem \"mocha\"\ngem \"minitest\"\ngem \"appraisal\"\ngem \"activesupport\", \"~> 5.2.0\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/activesupport6.0.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"rake\"\ngem \"mocha\"\ngem \"minitest\"\ngem \"appraisal\"\ngem \"activesupport\", \"~> 6.0.0\"\ngem \"base64\"\ngem \"bigdecimal\"\ngem \"mutex_m\"\ngem \"benchmark\"\ngem \"logger\"\ngem \"concurrent-ruby\", \"1.3.4\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/activesupport6.1.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"rake\"\ngem \"mocha\"\ngem \"minitest\"\ngem \"appraisal\"\ngem \"activesupport\", \"~> 6.1.0\"\ngem \"base64\"\ngem \"bigdecimal\"\ngem \"mutex_m\"\ngem \"benchmark\"\ngem \"logger\"\ngem \"concurrent-ruby\", \"1.3.4\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/activesupport7.0.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"rake\"\ngem \"mocha\"\ngem \"minitest\"\ngem \"appraisal\"\ngem \"activesupport\", \"~> 7.0.0\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/activesupport7.1.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"rake\"\ngem \"mocha\"\ngem \"minitest\"\ngem \"appraisal\"\ngem \"activesupport\", \"~> 7.1.0\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/activesupport7.2.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"rake\"\ngem \"mocha\"\ngem \"minitest\"\ngem \"appraisal\"\ngem \"activesupport\", \"~> 7.2.0\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/activesupport8.0.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"rake\"\ngem \"mocha\"\ngem \"minitest\"\ngem \"appraisal\"\ngem \"activesupport\", \"~> 8.0.0\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/activesupport8.1.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"rake\"\ngem \"mocha\"\ngem \"minitest\"\ngem \"appraisal\"\ngem \"activesupport\", \"~> 8.1.0\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "lib/whenever/capistrano/v2/hooks.rb",
    "content": "require \"whenever/capistrano/v2/recipes\"\n\nCapistrano::Configuration.instance(:must_exist).load do\n  # Write the new cron jobs near the end.\n  before \"deploy:finalize_update\", \"whenever:update_crontab\"\n  # If anything goes wrong, undo.\n  after \"deploy:rollback\", \"whenever:update_crontab\"\nend\n"
  },
  {
    "path": "lib/whenever/capistrano/v2/recipes.rb",
    "content": "require 'whenever/capistrano/v2/support'\n\nCapistrano::Configuration.instance(:must_exist).load do\n  Whenever::CapistranoSupport.load_into(self)\n\n  _cset(:whenever_roles)        { :db }\n  _cset(:whenever_options)      { {:roles => fetch(:whenever_roles)} }\n  _cset(:whenever_command)      { \"whenever\" }\n  _cset(:whenever_identifier)   { fetch :application }\n  _cset(:whenever_environment)  { fetch :rails_env, fetch(:stage, \"production\") }\n  _cset(:whenever_variables)    { \"environment=#{fetch :whenever_environment}\" }\n  _cset(:whenever_update_flags) { \"--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}\" }\n  _cset(:whenever_clear_flags)  { \"--clear-crontab #{fetch :whenever_identifier}\" }\n  _cset(:whenever_path)         { fetch :latest_release }\n\n  namespace :whenever do\n    desc \"Update application's crontab entries using Whenever\"\n    task :update_crontab do\n      args = {\n        :command => fetch(:whenever_command),\n        :flags   => fetch(:whenever_update_flags),\n        :path    => fetch(:whenever_path)\n      }\n\n      if whenever_servers.any?\n        args = whenever_prepare_for_rollback(args) if task_call_frames[0].task.fully_qualified_name == 'deploy:rollback'\n        whenever_run_commands(args)\n\n        on_rollback do\n          args = whenever_prepare_for_rollback(args)\n          whenever_run_commands(args)\n        end\n      end\n    end\n\n    desc \"Clear application's crontab entries using Whenever\"\n    task :clear_crontab do\n      if whenever_servers.any?\n        args = {\n          :command => fetch(:whenever_command),\n          :flags   => fetch(:whenever_clear_flags),\n          :path    => fetch(:whenever_path)\n        }\n\n        whenever_run_commands(args)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/whenever/capistrano/v2/support.rb",
    "content": "module Whenever\n  module CapistranoSupport\n    def self.load_into(capistrano_configuration)\n      capistrano_configuration.load do\n\n        def whenever_options\n          fetch(:whenever_options)\n        end\n\n        def whenever_roles\n          Array(whenever_options[:roles])\n        end\n\n        def whenever_servers\n          find_servers(whenever_options)\n        end\n\n        def whenever_server_roles\n          whenever_servers.inject({}) do |map, server|\n            map[server] = role_names_for_host(server) & whenever_roles\n            map\n          end\n        end\n\n        def whenever_prepare_for_rollback args\n          if fetch(:previous_release)\n            # rollback to the previous release's crontab\n            args[:path] = fetch(:previous_release)\n          else\n            # clear the crontab if no previous release\n            args[:path]  = fetch(:release_path)\n            args[:flags] = fetch(:whenever_clear_flags)\n          end\n          args\n        end\n\n        def whenever_run_commands(args)\n          unless [:command, :path, :flags].all? { |a| args.include?(a) }\n            raise ArgumentError, \":command, :path, & :flags are required\"\n          end\n\n          whenever_server_roles.each do |server, roles|\n            roles_arg = roles.empty? ? \"\" : \" --roles #{roles.join(',')}\"\n\n            command = \"cd #{args[:path]} && #{args[:command]} #{args[:flags]}#{roles_arg}\"\n            run command, whenever_options.merge(:hosts => server)\n          end\n        end\n\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/whenever/capistrano/v3/tasks/whenever.rake",
    "content": "namespace :whenever do\n  def setup_whenever_task(*args, &block)\n    args = Array(fetch(:whenever_command)) + args\n\n    on roles *fetch(:whenever_roles) do |host|\n      args_for_host = block_given? ? args + Array(yield(host)) : args\n      within fetch(:whenever_path) do\n        with fetch(:whenever_command_environment_variables) do\n          execute(*args_for_host)\n        end\n      end\n    end\n  end\n\n  def load_file\n    file = fetch(:whenever_load_file)\n    if file\n      \"-f #{file}\"\n    else\n      ''\n    end\n  end\n\n  desc \"Update application's crontab entries using Whenever\"\n  task :update_crontab do\n    setup_whenever_task do |host|\n      roles = host.roles_array.join(\",\")\n      [fetch(:whenever_update_flags), \"--roles=#{roles}\", load_file]\n    end\n  end\n\n  desc \"Clear application's crontab entries using Whenever\"\n  task :clear_crontab do\n    setup_whenever_task do |host|\n      [fetch(:whenever_clear_flags), load_file]\n    end\n  end\n\n  after \"deploy:updated\",  \"whenever:update_crontab\"\n  after \"deploy:reverted\", \"whenever:update_crontab\"\nend\n\nnamespace :load do\n  task :defaults do\n    set :whenever_roles,        ->{ :db }\n    set :whenever_command,      ->{ [:bundle, :exec, :whenever] }\n    set :whenever_command_environment_variables, ->{ fetch(:default_env).merge(rails_env: fetch(:whenever_environment)) }\n    set :whenever_identifier,   ->{ fetch :application }\n    set :whenever_environment,  ->{ fetch :rails_env, fetch(:stage, \"production\") }\n    set :whenever_variables,    ->{ \"environment=#{fetch :whenever_environment}\" }\n    set :whenever_load_file,    ->{ nil }\n    set :whenever_update_flags, ->{ \"--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}\" }\n    set :whenever_clear_flags,  ->{ \"--clear-crontab #{fetch :whenever_identifier}\" }\n    set :whenever_path,         ->{ release_path }\n  end\nend\n"
  },
  {
    "path": "lib/whenever/capistrano.rb",
    "content": "require 'capistrano/version'\n\nif defined?(Capistrano::VERSION) && Gem::Version.new(Capistrano::VERSION).release >= Gem::Version.new('3.0.0')\n  load File.expand_path(\"../capistrano/v3/tasks/whenever.rake\", __FILE__)\nelse\n  require 'whenever/capistrano/v2/hooks'\nend\n"
  },
  {
    "path": "lib/whenever/command_line.rb",
    "content": "require 'fileutils'\n\nmodule Whenever\n  class CommandLine\n    def self.execute(options={})\n      new(options).run\n    end\n\n    def initialize(options={})\n      @options = options\n\n      @options[:crontab_command] ||= 'crontab'\n      @options[:file]            ||= 'config/schedule.rb'\n      @options[:cut]             ||= 0\n      @options[:identifier]      ||= default_identifier\n      @options[:console]    = true if @options[:console].nil?\n\n      if !File.exist?(@options[:file]) && @options[:clear].nil?\n        warn(\"[fail] Can't find file: #{@options[:file]}\")\n        return_or_exit(false)\n      end\n\n      if [@options[:update], @options[:write], @options[:clear]].compact.length > 1\n        warn(\"[fail] Can only update, write or clear. Choose one.\")\n        return_or_exit(false)\n      end\n\n      unless @options[:cut].to_s =~ /[0-9]*/\n        warn(\"[fail] Can't cut negative lines from the crontab #{options[:cut]}\")\n        return_or_exit(false)\n      end\n      @options[:cut] = @options[:cut].to_i\n\n      @timestamp = Time.now.to_s\n    end\n\n    def run\n      if @options[:update] || @options[:clear]\n        write_crontab(updated_crontab)\n      elsif @options[:write]\n        write_crontab(whenever_cron)\n      else\n        puts Whenever.cron(@options)\n        puts \"## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.\"\n        puts \"## [message] Run `whenever --help' for more options.\"\n        return_or_exit(true)\n      end\n    end\n\n  protected\n\n    def default_identifier\n      File.expand_path(@options[:file])\n    end\n\n    def whenever_cron\n      return '' if @options[:clear]\n      @whenever_cron ||= [comment_open, Whenever.cron(@options), comment_close].compact.join(\"\\n\") + \"\\n\"\n    end\n\n    def read_crontab\n      return @current_crontab if instance_variable_defined?(:@current_crontab)\n\n      command = [@options[:crontab_command]]\n      command << '-l'\n      command << \"-u #{@options[:user]}\" if @options[:user]\n\n      command_results  = %x[#{command.join(' ')} 2> /dev/null]\n      @current_crontab = $?.exitstatus.zero? ? prepare(command_results) : ''\n    end\n\n    def write_crontab(contents)\n      command = [@options[:crontab_command]]\n      command << \"-u #{@options[:user]}\" if @options[:user]\n      # Solaris/SmartOS cron does not support the - option to read from stdin.\n      command << \"-\" unless OS.solaris?\n\n      IO.popen(command.join(' '), 'r+') do |crontab|\n        crontab.write(contents)\n        crontab.close_write\n        stdout = crontab.read\n        puts stdout unless stdout == ''\n      end\n\n      success = $?.exitstatus.zero?\n\n      if success\n        action = 'written' if @options[:write]\n        action = 'updated' if @options[:update]\n        puts \"[write] crontab file #{action}\"\n        return_or_exit(true)\n      else\n        warn \"[fail] Couldn't write crontab; try running `whenever' with no options to ensure your schedule file is valid.\"\n        return_or_exit(false)\n      end\n    end\n\n    def updated_crontab\n      # Check for unopened or unclosed identifier blocks\n      if read_crontab =~ Regexp.new(\"^#{comment_open_regex}\\s*$\") && (read_crontab =~ Regexp.new(\"^#{comment_close_regex}\\s*$\")).nil?\n        warn \"[fail] Unclosed indentifier; Your crontab file contains '#{comment_open(false)}', but no '#{comment_close(false)}'\"\n        return_or_exit(false)\n      elsif (read_crontab =~ Regexp.new(\"^#{comment_open_regex}\\s*$\")).nil? && read_crontab =~ Regexp.new(\"^#{comment_close_regex}\\s*$\")\n        warn \"[fail] Unopened indentifier; Your crontab file contains '#{comment_close(false)}', but no '#{comment_open(false)}'\"\n        return_or_exit(false)\n      end\n\n      # If an existing identifier block is found, replace it with the new cron entries\n      if read_crontab =~ Regexp.new(\"^#{comment_open_regex}\\s*$\") && read_crontab =~ Regexp.new(\"^#{comment_close_regex}\\s*$\")\n        # If the existing crontab file contains backslashes they get lost going through gsub.\n        # .gsub('\\\\', '\\\\\\\\\\\\') preserves them. Go figure.\n        read_crontab.gsub(Regexp.new(\"^#{comment_open_regex}\\s*$.+^#{comment_close_regex}\\s*$\", Regexp::MULTILINE), whenever_cron.chomp.gsub('\\\\', '\\\\\\\\\\\\'))\n      else # Otherwise, append the new cron entries after any existing ones\n        [read_crontab, whenever_cron].join(\"\\n\\n\")\n      end.gsub(/\\n{3,}/, \"\\n\\n\") # More than two newlines becomes just two.\n    end\n\n    def prepare(contents)\n      # Strip n lines from the top of the file as specified by the :cut option.\n      # Use split with a -1 limit option to ensure the join is able to rebuild\n      # the file with all of the original seperators in-tact.\n      stripped_contents = contents.split($/,-1)[@options[:cut]..-1].join($/)\n\n      # Some cron implementations require all non-comment lines to be newline-\n      # terminated. (issue #95) Strip all newlines and replace with the default\n      # platform record seperator ($/)\n      stripped_contents.gsub!(/\\s+$/, $/)\n    end\n\n    def comment_base(include_timestamp = true)\n      if include_timestamp\n        \"Whenever generated tasks for: #{@options[:identifier]} at: #{@timestamp}\"\n      else\n        \"Whenever generated tasks for: #{@options[:identifier]}\"\n      end\n    end\n\n    def comment_open(include_timestamp = true)\n      \"# Begin #{comment_base(include_timestamp)}\"\n    end\n\n    def comment_close(include_timestamp = true)\n      \"# End #{comment_base(include_timestamp)}\"\n    end\n\n    def comment_open_regex\n      \"#{comment_open(false)}(#{timestamp_regex}|)\"\n    end\n\n    def comment_close_regex\n      \"#{comment_close(false)}(#{timestamp_regex}|)\"\n    end\n\n    def timestamp_regex\n      \" at: \\\\d{4}-\\\\d{2}-\\\\d{2} \\\\d{2}:\\\\d{2}:\\\\d{2} ([+-]\\\\d{4}|UTC)\"\n    end\n\n  private\n\n    def return_or_exit success\n      result = 1\n      result = 0 if success\n      if @options[:console]\n        exit(result)\n      else\n        result\n      end\n    end\n\n  end\nend\n"
  },
  {
    "path": "lib/whenever/cron.rb",
    "content": "require 'chronic'\n\nmodule Whenever\n  module Output\n    class Cron\n      DAYS = %w(sun mon tue wed thu fri sat)\n      MONTHS = %w(jan feb mar apr may jun jul aug sep oct nov dec)\n      KEYWORDS = [:reboot, :yearly, :annually, :monthly, :weekly, :daily, :midnight, :hourly]\n      REGEX = /^(@(#{KEYWORDS.join '|'})|((\\*?[\\d\\/,\\-]*)\\s){3}(\\*?([\\d\\/,\\-]|(#{MONTHS.join '|'}))*\\s)(\\*?([\\d\\/,\\-]|(#{DAYS.join '|'}))*))$/i\n\n      attr_accessor :time, :task\n\n      def initialize(time = nil, task = nil, at = nil, options = {})\n        chronic_options = options[:chronic_options] || {}\n\n        @at_given = at\n        @time = time\n        @task = task\n        @at   = at.is_a?(String) ? (Chronic.parse(at, chronic_options) || 0) : (at || 0)\n      end\n\n      def self.enumerate(item, detect_cron = true)\n        if item and item.is_a?(String)\n          items =\n            if detect_cron && item =~ REGEX\n              [item]\n            else\n              item.split(',')\n            end\n        else\n          items = item\n          items = [items] unless items and items.respond_to?(:each)\n        end\n        items\n      end\n\n      def self.output(times, job, options = {})\n        enumerate(times).each do |time|\n          enumerate(job.at, false).each do |at|\n            yield new(time, job.output, at, options).output\n          end\n        end\n      end\n\n      def output\n        [time_in_cron_syntax, task].compact.join(' ').strip\n      end\n\n      def time_in_cron_syntax\n        @time = @time.to_i if @time.is_a?(Numeric) # Compatibility with `1.day` format using ruby 2.3 and activesupport\n        case @time\n          when REGEX  then @time # raw cron syntax given\n          when Symbol then parse_symbol\n          when String then parse_as_string\n          else parse_time\n        end\n      end\n\n    protected\n      def day_given?\n        @at_given.is_a?(String) && (MONTHS.any? { |m| @at_given.downcase.index(m) } || @at_given[/\\d\\/\\d/])\n      end\n\n      def parse_symbol\n        shortcut = case @time\n          when *KEYWORDS then \"@#{@time}\" # :reboot => '@reboot'\n          when :year     then Whenever.seconds(1, :year)\n          when :day      then Whenever.seconds(1, :day)\n          when :month    then Whenever.seconds(1, :month)\n          when :week     then Whenever.seconds(1, :week)\n          when :hour     then Whenever.seconds(1, :hour)\n          when :minute   then Whenever.seconds(1, :minute)\n        end\n\n        if shortcut.is_a?(Numeric)\n          @time = shortcut\n          parse_time\n        elsif shortcut\n          if @at.is_a?(Time) || (@at.is_a?(Numeric) && @at > 0)\n            raise ArgumentError, \"You cannot specify an ':at' when using the shortcuts for times.\"\n          else\n            return shortcut\n          end\n        else\n          parse_as_string\n        end\n      end\n\n      def parse_time\n        timing = Array.new(5, '*')\n        case @time\n          when Whenever.seconds(0, :seconds)...Whenever.seconds(1, :minute)\n            raise ArgumentError, \"Time must be in minutes or higher\"\n          when Whenever.seconds(1, :minute)...Whenever.seconds(1, :hour)\n            minute_frequency = @time / 60\n            timing[0] = comma_separated_timing(minute_frequency, 59, @at || 0)\n          when Whenever.seconds(1, :hour)...Whenever.seconds(1, :day)\n            hour_frequency = (@time / 60 / 60).round\n            timing[0] = @at.is_a?(Time) ? @at.min : range_or_integer(@at, 0..59, 'Minute')\n            timing[1] = comma_separated_timing(hour_frequency, 23)\n          when Whenever.seconds(1, :day)...Whenever.seconds(1, :month)\n            day_frequency = (@time / 24 / 60 / 60).round\n            timing[0] = @at.is_a?(Time) ? @at.min  : 0\n            timing[1] = @at.is_a?(Time) ? @at.hour : range_or_integer(@at, 0..23, 'Hour')\n            timing[2] = comma_separated_timing(day_frequency, 31, 1)\n          when Whenever.seconds(1, :month)...Whenever.seconds(1, :year)\n            month_frequency = (@time / 30 / 24 / 60 / 60).round\n            timing[0] = @at.is_a?(Time) ? @at.min  : 0\n            timing[1] = @at.is_a?(Time) ? @at.hour : 0\n            timing[2] = if @at.is_a?(Time)\n              day_given? ? @at.day : 1\n            else\n              @at == 0 ? 1 : range_or_integer(@at, 1..31, 'Day')\n            end\n            timing[3] = comma_separated_timing(month_frequency, 12, 1)\n          when Whenever.seconds(1, :year)\n            timing[0] = @at.is_a?(Time) ? @at.min  : 0\n            timing[1] = @at.is_a?(Time) ? @at.hour : 0\n            timing[2] = if @at.is_a?(Time)\n              day_given? ? @at.day : 1\n            else\n              1\n            end\n            timing[3] = if @at.is_a?(Time)\n              day_given? ? @at.month : 1\n            else\n              @at == 0 ? 1 : range_or_integer(@at, 1..12, 'Month')\n            end\n          else\n            return parse_as_string\n        end\n        timing.join(' ')\n      end\n\n      def parse_as_string\n        return unless @time\n        string = @time.to_s\n\n        timing = Array.new(4, '*')\n        timing[0] = @at.is_a?(Time) ? @at.min  : 0\n        timing[1] = @at.is_a?(Time) ? @at.hour : 0\n\n        return (timing << '1-5') * \" \" if string.downcase.index('weekday')\n        return (timing << '6,0') * \" \" if string.downcase.index('weekend')\n\n        DAYS.each_with_index do |day, i|\n          return (timing << i) * \" \" if string.downcase.index(day)\n        end\n\n        raise ArgumentError, \"Couldn't parse: #{@time.inspect}\"\n      end\n\n      def range_or_integer(at, valid_range, name)\n        must_be_between = \"#{name} must be between #{valid_range.min}-#{valid_range.max}\"\n        if at.is_a?(Range)\n          raise ArgumentError, \"#{must_be_between}, #{at.min} given\" unless valid_range.include?(at.min)\n          raise ArgumentError, \"#{must_be_between}, #{at.max} given\" unless valid_range.include?(at.max)\n          return \"#{at.min}-#{at.max}\"\n        end\n        raise ArgumentError, \"#{must_be_between}, #{at} given\" unless valid_range.include?(at)\n        at\n      end\n\n      def comma_separated_timing(frequency, max, start = 0)\n        return start     if frequency.nil? || frequency == \"\" || frequency.zero?\n        return '*'       if frequency == 1\n        return frequency if frequency > (max * 0.5).ceil\n\n        original_start = start\n\n        start += frequency unless (max + 1).modulo(frequency).zero? || start > 0\n        output = (start..max).step(frequency).to_a\n\n        max_occurances = (max.to_f  / (frequency.to_f)).round\n        max_occurances += 1 if original_start.zero?\n\n        output[0, max_occurances].join(',')\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/whenever/job.rb",
    "content": "require 'shellwords'\n\nmodule Whenever\n  class Job\n    attr_reader :at, :roles, :mailto, :description\n\n    def initialize(options = {})\n      @options = options\n      @at                               = options.delete(:at)\n      @template                         = options.delete(:template)\n      @mailto                           = options.fetch(:mailto, :default_mailto)\n      @job_template                     = options.delete(:job_template) || \":job\"\n      @roles                            = Array(options.delete(:roles))\n      @description                      = options.delete(:description)\n      @options[:output]                 = options.has_key?(:output) ? Whenever::Output::Redirection.new(options[:output]).to_s : ''\n      @options[:environment_variable] ||= \"RAILS_ENV\"\n      @options[:environment]          ||= :production\n      @options[:path]                   = Shellwords.shellescape(@options[:path] || Whenever.path)\n    end\n\n    def output\n      job = process_template(@template, @options)\n      out = process_template(@job_template, @options.merge(:job => job))\n      out.gsub(/%/, '\\%')\n    end\n\n    def has_role?(role)\n      roles.empty? || roles.include?(role)\n    end\n\n  protected\n\n    def process_template(template, options)\n      template.gsub(/:\\w+/) do |key|\n        before_and_after = [$`[-1..-1], $'[0..0]]\n        option = options[key.sub(':', '').to_sym] || key\n\n        if before_and_after.all? { |c| c == \"'\" }\n          escape_single_quotes(option)\n        elsif before_and_after.all? { |c| c == '\"' }\n          escape_double_quotes(option)\n        else\n          option\n        end\n      end.gsub(/\\s+/m, \" \").strip\n    end\n\n    def escape_single_quotes(str)\n      str.gsub(/'/) { \"'\\\\''\" }\n    end\n\n    def escape_double_quotes(str)\n      str.gsub(/\"/) { '\\\"' }\n    end\n  end\nend\n"
  },
  {
    "path": "lib/whenever/job_list.rb",
    "content": "module Whenever\n  class JobList\n    attr_reader :roles\n\n    def initialize(options)\n      @jobs, @env, @set_variables, @pre_set_variables = {}, {}, {}, {}\n\n      if options.is_a? String\n        options = { :string => options }\n      end\n\n      pre_set(options[:set])\n\n      @roles = options[:roles] || []\n\n      setup_file = File.expand_path('../setup.rb', __FILE__)\n      setup = File.read(setup_file)\n      schedule = if options[:string]\n        options[:string]\n      elsif options[:file]\n        File.read(options[:file])\n      end\n\n      instance_eval(setup, setup_file)\n      instance_eval(schedule, options[:file] || '<eval>')\n    end\n\n    def set(variable, value)\n      variable = variable.to_sym\n      return if @pre_set_variables[variable]\n\n      instance_variable_set(\"@#{variable}\".to_sym, value)\n      @set_variables[variable] = value\n    end\n\n    def method_missing(name, *args, &block)\n      @set_variables.has_key?(name) ? @set_variables[name] : super\n    end\n\n    def respond_to?(name, include_private = false)\n      @set_variables.has_key?(name) || super\n    end\n\n    def env(variable, value)\n      @env[variable.to_s] = value\n    end\n\n    def every(frequency, options = {})\n      @current_time_scope = frequency\n      @options = options\n      yield\n    end\n\n    def job_type(name, template)\n      singleton_class.class_eval do\n        define_method(name) do |task, *args|\n          options = { :task => task, :template => template }\n          options.merge!(args[0]) if args[0].is_a? Hash\n\n          options[:mailto] ||= @options.fetch(:mailto, :default_mailto)\n\n          # :cron_log was an old option for output redirection, it remains for backwards compatibility\n          options[:output] = (options[:cron_log] || @cron_log) if defined?(@cron_log) || options.has_key?(:cron_log)\n          # :output is the newer, more flexible option.\n          options[:output] = @output if defined?(@output) && !options.has_key?(:output)\n\n          @jobs[options.fetch(:mailto)] ||= {}\n          @jobs[options.fetch(:mailto)][@current_time_scope] ||= []\n          @jobs[options.fetch(:mailto)][@current_time_scope] << Whenever::Job.new(@set_variables.merge(@options).merge(options))\n        end\n      end\n    end\n\n    def generate_cron_output\n      [environment_variables, cron_jobs].compact.join\n    end\n\n  private\n\n    #\n    # Takes a string like: \"variable1=something&variable2=somethingelse\"\n    # and breaks it into variable/value pairs. Used for setting variables at runtime from the command line.\n    # Only works for setting values as strings.\n    #\n    def pre_set(variable_string = nil)\n      return if variable_string.nil? || variable_string == \"\"\n\n      pairs = variable_string.split('&')\n      pairs.each do |pair|\n        next unless pair.index('=')\n        variable, value = *pair.split('=')\n        unless variable.nil? || variable == \"\" || value.nil? || value == \"\"\n          variable = variable.strip.to_sym\n          set(variable, value.strip)\n          @pre_set_variables[variable] = value\n        end\n      end\n    end\n\n    def environment_variables\n      return if @env.empty?\n\n      output = []\n      @env.each do |key, val|\n        output << \"#{key}=#{val.nil? || val == \"\" ? '\"\"' : val}\\n\"\n      end\n      output << \"\\n\"\n\n      output.join\n    end\n\n    #\n    # Takes the standard cron output that Whenever generates and finds\n    # similar entries that can be combined. For example: If a job should run\n    # at 3:02am and 4:02am, instead of creating two jobs this method combines\n    # them into one that runs on the 2nd minute at the 3rd and 4th hour.\n    #\n    def combine(entries)\n      entries.map! { |entry| entry.split(/ +/, 6) }\n      0.upto(4) do |f|\n        (entries.length-1).downto(1) do |i|\n          next if entries[i][f] == '*'\n          comparison = entries[i][0...f] + entries[i][f+1..-1]\n          (i-1).downto(0) do |j|\n            next if entries[j][f] == '*'\n            if comparison == entries[j][0...f] + entries[j][f+1..-1]\n              entries[j][f] += ',' + entries[i][f]\n              entries.delete_at(i)\n              break\n            end\n          end\n        end\n      end\n\n      entries.map { |entry| entry.join(' ') }\n    end\n\n    def cron_jobs_of_time(time, jobs)\n      shortcut_jobs, regular_jobs = [], []\n\n      jobs.each do |job|\n        next unless roles.empty? || roles.any? do |r|\n          job.has_role?(r)\n        end\n        Whenever::Output::Cron.output(time, job, :chronic_options => @chronic_options) do |cron|\n          cron << \"\\n\\n\"\n          cron = (job.description.strip + \"\\n\").gsub(/^(.*)$/, '# \\1') + cron unless job.description.to_s.empty?\n\n          if cron[0,1] == \"@\"\n            shortcut_jobs << cron\n          else\n            regular_jobs << cron\n          end\n        end\n      end\n\n      shortcut_jobs.join + combine(regular_jobs).join\n    end\n\n    def cron_jobs\n      return if @jobs.empty?\n\n      output = []\n\n      # jobs with default mailto's must be output before the ones with non-default mailto's.\n      @jobs.delete(:default_mailto) { Hash.new }.each do |time, jobs|\n        output << cron_jobs_of_time(time, jobs)\n      end\n\n      @jobs.each do |mailto, time_and_jobs|\n        output_jobs = []\n\n        time_and_jobs.each do |time, jobs|\n          output_jobs << cron_jobs_of_time(time, jobs)\n        end\n\n        output_jobs.reject! { |output_job| output_job.empty? }\n\n        output << \"MAILTO=#{mailto}\\n\\n\" unless output_jobs.empty?\n        output << output_jobs\n      end\n\n      output.join\n    end\n  end\nend\n"
  },
  {
    "path": "lib/whenever/numeric.rb",
    "content": "Numeric.class_eval do\n  def respond_to?(method, include_private = false)\n    super || Whenever::NumericSeconds.public_method_defined?(method)\n  end\n\n  def method_missing(method, *args, &block)\n    if Whenever::NumericSeconds.public_method_defined?(method)\n      Whenever::NumericSeconds.new(self).send(method)\n    else\n      super\n    end\n  end\nend\n"
  },
  {
    "path": "lib/whenever/numeric_seconds.rb",
    "content": "module Whenever\n  class NumericSeconds\n    attr_reader :number\n\n    def self.seconds(number, units)\n      new(number).send(units)\n    end\n\n    def initialize(number)\n      @number = number.to_i\n    end\n\n    def seconds\n      number\n    end\n    alias :second :seconds\n\n    def minutes\n      number * 60\n    end\n    alias :minute :minutes\n\n    def hours\n      number * 3_600\n    end\n    alias :hour :hours\n\n    def days\n      number * 86_400\n    end\n    alias :day :days\n\n    def weeks\n      number * 604_800\n    end\n    alias :week :weeks\n\n    def months\n      number * 2_592_000\n    end\n    alias :month :months\n\n    def years\n      number * 31_557_600\n    end\n    alias :year :years\n  end\nend\n"
  },
  {
    "path": "lib/whenever/os.rb",
    "content": "module Whenever\n  module OS\n    def self.solaris?\n      (/solaris/ =~ RUBY_PLATFORM)\n    end\n  end\nend\n"
  },
  {
    "path": "lib/whenever/output_redirection.rb",
    "content": "module Whenever\n  module Output\n    class Redirection\n      def initialize(output)\n        @output = output\n      end\n      \n      def to_s\n        return '' unless defined?(@output)\n        case @output\n          when String   then redirect_from_string\n          when Hash     then redirect_from_hash\n          when NilClass then \">> /dev/null 2>&1\"\n          when Proc     then @output.call\n          else ''\n        end \n      end\n      \n    protected\n      \n      def stdout\n        return unless @output.has_key?(:standard)\n        @output[:standard].nil? ? '/dev/null' : @output[:standard]\n      end\n\n      def stderr\n        return unless @output.has_key?(:error)\n        @output[:error].nil? ? '/dev/null' : @output[:error]\n      end\n\n      def redirect_from_hash\n        case\n          when stdout == '/dev/null' && stderr == '/dev/null'\n            \"> /dev/null 2>&1\"\n          when stdout && stderr == '/dev/null'\n            \">> #{stdout} 2> /dev/null\"\n          when stdout && stderr\n            \">> #{stdout} 2>> #{stderr}\"\n          when stderr == '/dev/null'\n            \"2> /dev/null\"\n          when stderr\n            \"2>> #{stderr}\"\n          when stdout == '/dev/null'\n            \"> /dev/null\"\n          when stdout\n            \">> #{stdout}\"\n          else\n            ''\n        end\n      end\n\n      def redirect_from_string\n        \">> #{@output} 2>&1\"\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/whenever/setup.rb",
    "content": "# Environment variable defaults to RAILS_ENV\nset :environment_variable, \"RAILS_ENV\"\n# Environment defaults to the value of RAILS_ENV in the current environment if\n# it's set or production otherwise\nset :environment, ENV.fetch(\"RAILS_ENV\", \"production\")\n# Path defaults to the directory `whenever` was run from\nset :path, Whenever.path\n\n# Custom Chronic configuration for time parsing, empty by default\n# Full list of options at: https://github.com/mojombo/chronic/blob/master/lib/chronic/parser.rb\nset :chronic_options, {}\n\n# All jobs are wrapped in this template.\n# http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production\nset :job_template, \"/bin/bash -l -c ':job'\"\n\nset :runner_command, case\n  when Whenever.bin_rails?\n    \"bin/rails runner\"\n  when Whenever.script_rails?\n    \"script/rails runner\"\n  else\n    \"script/runner\"\n  end\n\nset :bundle_command, Whenever.bundler? ? \"bundle exec\" : \"\"\n\njob_type :command, \":task :output\"\njob_type :rake,    \"cd :path && :environment_variable=:environment :bundle_command rake :task --silent :output\"\njob_type :script,  \"cd :path && :environment_variable=:environment :bundle_command script/:task :output\"\njob_type :runner,  \"cd :path && :bundle_command :runner_command -e :environment ':task' :output\"\n"
  },
  {
    "path": "lib/whenever/version.rb",
    "content": "module Whenever\n  VERSION = '1.1.2'\nend\n"
  },
  {
    "path": "lib/whenever.rb",
    "content": "require \"whenever/version\"\nrequire 'whenever/numeric'\nrequire 'whenever/numeric_seconds'\nrequire 'whenever/job_list'\nrequire 'whenever/job'\nrequire 'whenever/command_line'\nrequire 'whenever/cron'\nrequire 'whenever/output_redirection'\nrequire 'whenever/os'\n\nmodule Whenever\n  def self.cron(options)\n    Whenever::JobList.new(options).generate_cron_output\n  end\n\n  def self.seconds(number, units)\n    Whenever::NumericSeconds.seconds(number, units)\n  end\n\n  def self.path\n    Dir.pwd\n  end\n\n  def self.bin_rails?\n    File.exist?(File.join(path, 'bin', 'rails'))\n  end\n\n  def self.script_rails?\n    File.exist?(File.join(path, 'script', 'rails'))\n  end\n\n  def self.bundler?\n    File.exist?(File.join(path, 'Gemfile'))\n  end\n\n  def self.update_cron options\n    o = { 'update' => true, 'console' => false}\n    o.merge! options if options\n    Whenever::CommandLine.execute o\n  end\n\nend\n"
  },
  {
    "path": "test/functional/command_line_test.rb",
    "content": "require 'test_helper'\n\nclass CommandLineWriteTest < Whenever::TestCase\n  setup do\n    Time.stubs(:now).returns(Time.new(2017, 2, 24, 16, 21, 30, '+01:00'))\n    File.expects(:exist?).with('config/schedule.rb').returns(true)\n    @command = Whenever::CommandLine.new(:write => true, :identifier => 'My identifier')\n    @task = \"#{two_hours} /my/command\"\n    Whenever.expects(:cron).returns(@task)\n  end\n\n  should \"output the cron job with identifier blocks\" do\n    output = <<-EXPECTED\n# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\n#{@task}\n# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\nEXPECTED\n\n    assert_equal output, @command.send(:whenever_cron)\n  end\n\n  should \"write the crontab when run\" do\n    @command.expects(:write_crontab).returns(true)\n    assert @command.run\n  end\nend\n\nclass CommandLineUpdateTest < Whenever::TestCase\n  setup do\n    Time.stubs(:now).returns(Time.new(2017, 2, 24, 16, 21, 30, '+01:00'))\n    File.expects(:exist?).with('config/schedule.rb').returns(true)\n    @command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier')\n    @task = \"#{two_hours} /my/command\"\n    Whenever.expects(:cron).returns(@task)\n  end\n\n  should \"add the cron to the end of the file if there is no existing identifier block\" do\n    existing = '# Existing crontab'\n    @command.expects(:read_crontab).at_least_once.returns(existing)\n\n    new_cron = <<-EXPECTED\n#{existing}\n\n# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\n#{@task}\n# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\nEXPECTED\n\n    assert_equal new_cron, @command.send(:updated_crontab)\n\n    @command.expects(:write_crontab).with(new_cron).returns(true)\n    assert @command.run\n  end\n\n  should \"replace an existing block if the identifier matches and the timestamp doesn't\" do\n    existing = <<-EXISTING_CRON\n# Something\n\n# Begin Whenever generated tasks for: My identifier at: 2017-01-03 08:02:22 +0500\nMy whenever job that was already here\n# End Whenever generated tasks for: My identifier at: 2017-01-03 08:22:22 +0500\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nEXISTING_CRON\n\n    new_cron = <<-NEW_CRON\n# Something\n\n# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\n#{@task}\n# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nNEW_CRON\n\n    @command.expects(:read_crontab).at_least_once.returns(existing)\n    assert_equal new_cron, @command.send(:updated_crontab)\n\n    @command.expects(:write_crontab).with(new_cron).returns(true)\n    assert @command.run\n  end\n\n  should \"replace an existing block if the identifier matches and the UTC timestamp doesn't\" do\n    existing = <<-EXISTING_CRON\n# Something\n\n# Begin Whenever generated tasks for: My identifier at: 2017-01-03 08:02:22 UTC\nMy whenever job that was already here\n# End Whenever generated tasks for: My identifier at: 2017-01-03 08:22:22 UTC\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nEXISTING_CRON\n\n    new_cron = <<-NEW_CRON\n# Something\n\n# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\n#{@task}\n# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nNEW_CRON\n\n    @command.expects(:read_crontab).at_least_once.returns(existing)\n    assert_equal new_cron, @command.send(:updated_crontab)\n\n    @command.expects(:write_crontab).with(new_cron).returns(true)\n    assert @command.run\n  end\n\n  should \"replace an existing block if the identifier matches and it doesn't contain a timestamp\" do\n    existing = <<-EXISTING_CRON\n# Something\n\n# Begin Whenever generated tasks for: My identifier\nMy whenever job that was already here\n# End Whenever generated tasks for: My identifier\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nEXISTING_CRON\n\n    new_cron = <<-NEW_CRON\n# Something\n\n# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\n#{@task}\n# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nNEW_CRON\n\n    @command.expects(:read_crontab).at_least_once.returns(existing)\n    assert_equal new_cron, @command.send(:updated_crontab)\n\n    @command.expects(:write_crontab).with(new_cron).returns(true)\n    assert @command.run\n  end\nend\n\nclass CommandLineUpdateWithBackslashesTest < Whenever::TestCase\n  setup do\n    Time.stubs(:now).returns(Time.new(2017, 2, 24, 16, 21, 30, '+01:00'))\n    @existing = <<-EXISTING_CRON\n# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\nscript/runner -e production 'puts '\\\\''hello'\\\\'''\n# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\nEXISTING_CRON\n    File.expects(:exist?).with('config/schedule.rb').returns(true)\n    @command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier')\n    @command.expects(:read_crontab).at_least_once.returns(@existing)\n    @command.expects(:whenever_cron).returns(@existing)\n  end\n\n  should \"replace the existing block with the backslashes in tact\" do\n    assert_equal @existing, @command.send(:updated_crontab)\n  end\nend\n\nclass CommandLineUpdateToSimilarCrontabTest < Whenever::TestCase\n  setup do\n    @existing = <<-EXISTING_CRON\n# Begin Whenever generated tasks for: WheneverExisting at: 2017-02-24 16:21:30 +0100\n# End Whenever generated tasks for: WheneverExisting at: 2017-02-24 16:21:30 +0100\nEXISTING_CRON\n    @new = <<-NEW_CRON\n# Begin Whenever generated tasks for: Whenever at: 2017-02-24 16:21:30 +0100\n# End Whenever generated tasks for: Whenever at: 2017-02-24 16:21:30 +0100\nNEW_CRON\n    File.expects(:exist?).with('config/schedule.rb').returns(true)\n    @command = Whenever::CommandLine.new(:update => true, :identifier => 'Whenever')\n    @command.expects(:read_crontab).at_least_once.returns(@existing)\n    @command.expects(:whenever_cron).returns(@new)\n  end\n\n  should \"append the similarly named command\" do\n    assert_equal @existing + \"\\n\" + @new, @command.send(:updated_crontab)\n  end\nend\n\nclass CommandLineClearTest < Whenever::TestCase\n  setup do\n    Time.stubs(:now).returns(Time.new(2017, 2, 24, 16, 21, 30, '+01:00'))\n    File.expects(:exist?).with('config/schedule.rb').returns(true)\n    @command = Whenever::CommandLine.new(:clear => true, :identifier => 'My identifier')\n    @task = \"#{two_hours} /my/command\"\n  end\n\n  should \"clear an existing block if the identifier matches and the timestamp doesn't\" do\n    existing = <<-EXISTING_CRON\n# Something\n\n# Begin Whenever generated tasks for: My identifier at: 2017-01-03 08:20:02 +0500\nMy whenever job that was already here\n# End Whenever generated tasks for: My identifier at: 2017-01-03 08:20:02 +0500\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nEXISTING_CRON\n\n    @command.expects(:read_crontab).at_least_once.returns(existing)\n\n    new_cron = <<-NEW_CRON\n# Something\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nNEW_CRON\n\n    assert_equal new_cron, @command.send(:updated_crontab)\n\n    @command.expects(:write_crontab).with(new_cron).returns(true)\n    assert @command.run\n  end\n\n  should \"clear an existing block if the identifier matches and the UTC timestamp doesn't\" do\n    existing = <<-EXISTING_CRON\n# Something\n\n# Begin Whenever generated tasks for: My identifier at: 2017-01-03 08:20:02 UTC\nMy whenever job that was already here\n# End Whenever generated tasks for: My identifier at: 2017-01-03 08:20:02 UTC\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nEXISTING_CRON\n\n    @command.expects(:read_crontab).at_least_once.returns(existing)\n\n    new_cron = <<-NEW_CRON\n# Something\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nNEW_CRON\n\n    assert_equal new_cron, @command.send(:updated_crontab)\n\n    @command.expects(:write_crontab).with(new_cron).returns(true)\n    assert @command.run\n  end\n\n  should \"clear an existing block if the identifier matches and it doesn't have a timestamp\" do\n    existing = <<-EXISTING_CRON\n# Something\n\n# Begin Whenever generated tasks for: My identifier\nMy whenever job that was already here\n# End Whenever generated tasks for: My identifier\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nEXISTING_CRON\n\n    @command.expects(:read_crontab).at_least_once.returns(existing)\n\n    new_cron = <<-NEW_CRON\n# Something\n\n# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nThis shouldn't get replaced\n# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100\nNEW_CRON\n\n    assert_equal new_cron, @command.send(:updated_crontab)\n\n    @command.expects(:write_crontab).with(new_cron).returns(true)\n    assert @command.run\n  end\nend\n\nclass CommandLineClearWithNoScheduleTest < Whenever::TestCase\n  setup do\n    File.expects(:exist?).with('config/schedule.rb').returns(false)\n    @command = Whenever::CommandLine.new(:clear => true, :identifier => 'My identifier')\n  end\n\n  should \"run successfully\" do\n    @command.expects(:write_crontab).returns(true)\n    assert @command.run\n  end\nend\n\nclass CommandLineUpdateWithNoIdentifierTest < Whenever::TestCase\n  setup do\n    Time.stubs(:now).returns(Time.new(2017, 2, 24, 16, 21, 30, '+01:00'))\n    File.expects(:exist?).with('config/schedule.rb').returns(true)\n    Whenever::CommandLine.any_instance.expects(:default_identifier).returns('DEFAULT')\n    @command = Whenever::CommandLine.new(:update => true)\n  end\n\n  should \"use the default identifier\" do\n    assert_equal \"Whenever generated tasks for: DEFAULT at: 2017-02-24 16:21:30 +0100\", @command.send(:comment_base)\n  end\nend\n\nclass CombinedParamsTest < Whenever::TestCase\n  setup do\n    Whenever::CommandLine.any_instance.expects(:exit)\n    Whenever::CommandLine.any_instance.expects(:warn)\n    File.expects(:exist?).with('config/schedule.rb').returns(true)\n  end\n\n  should \"exit with write and clear\" do\n    @command = Whenever::CommandLine.new(:write => true, :clear => true)\n  end\n\n  should \"exit with write and update\" do\n    @command = Whenever::CommandLine.new(:write => true, :update => true)\n  end\n\n  should \"exit with update and clear\" do\n    @command = Whenever::CommandLine.new(:update => true, :clear => true)\n  end\nend\n\nclass RunnerOverwrittenWithSetOptionTest < Whenever::TestCase\n  setup do\n    @output = Whenever.cron :set => 'environment=serious', :string => \\\n    <<-file\n      set :job_template, nil\n      set :environment, :silly\n      set :path, '/my/path'\n      every 2.hours do\n        runner \"blahblah\"\n      end\n    file\n  end\n\n  should \"output the runner using the override environment\" do\n    assert_match two_hours + %( cd /my/path && bundle exec script/runner -e serious 'blahblah'), @output\n  end\nend\n\n\nclass EnvironmentAndPathOverwrittenWithSetOptionTest < Whenever::TestCase\n  setup do\n    @output = Whenever.cron :set => 'environment=serious&path=/serious/path', :string => \\\n    <<-file\n      set :job_template, nil\n      set :environment, :silly\n      set :path, '/silly/path'\n      every 2.hours do\n        runner \"blahblah\"\n      end\n    file\n  end\n\n  should \"output the runner using the overridden path and environment\" do\n    assert_match two_hours + %( cd /serious/path && bundle exec script/runner -e serious 'blahblah'), @output\n  end\nend\n\nclass EnvironmentAndPathOverwrittenWithSetOptionWithSpacesTest < Whenever::TestCase\n  setup do\n    @output = Whenever.cron :set => ' environment = serious&  path =/serious/path', :string => \\\n    <<-file\n      set :job_template, nil\n      set :environment, :silly\n      set :path, '/silly/path'\n      every 2.hours do\n        runner \"blahblah\"\n      end\n    file\n  end\n\n  should \"output the runner using the overridden path and environment\" do\n    assert_match two_hours + %( cd /serious/path && bundle exec script/runner -e serious 'blahblah'), @output\n  end\nend\n\nclass EnvironmentOverwrittenWithoutValueTest < Whenever::TestCase\n  setup do\n    @output = Whenever.cron :set => ' environment=', :string => \\\n    <<-file\n      set :job_template, nil\n      set :environment, :silly\n      set :path, '/silly/path'\n      every 2.hours do\n        runner \"blahblah\"\n      end\n    file\n  end\n\n  should \"output the runner using the original environment\" do\n    assert_match two_hours + %( cd /silly/path && bundle exec script/runner -e silly 'blahblah'), @output\n  end\nend\n\nclass PreparingOutputTest < Whenever::TestCase\n  setup do\n    File.expects(:exist?).with('config/schedule.rb').returns(true)\n  end\n\n  should \"not trim off the top lines of the file\" do\n    @command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier', :cut => 0)\n    existing = <<-EXISTING_CRON\n# Useless Comments\n# at the top of the file\n\n# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\nMy whenever job that was already here\n# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\nEXISTING_CRON\n\n    assert_equal existing, @command.send(:prepare, existing)\n  end\n\n  should \"trim off the top lines of the file\" do\n    @command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier', :cut => '3')\n    existing = <<-EXISTING_CRON\n# Useless Comments\n# at the top of the file\n\n# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\nMy whenever job that was already here\n# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\nEXISTING_CRON\n\n    new_cron = <<-NEW_CRON\n# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\nMy whenever job that was already here\n# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\nNEW_CRON\n\n    assert_equal new_cron, @command.send(:prepare, existing)\n  end\n\n  should \"preserve terminating newlines in files\" do\n    @command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier')\n    existing = <<-EXISTING_CRON\n# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\nMy whenever job that was already here\n# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100\n\n# A non-Whenever task\nMy non-whenever job that was already here\nEXISTING_CRON\n\n    assert_equal existing, @command.send(:prepare, existing)\n  end\nend\n"
  },
  {
    "path": "test/functional/output_at_test.rb",
    "content": "require 'test_helper'\n\nclass OutputAtTest < Whenever::TestCase\n  test \"weekday at a (single) given time\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every \"weekday\", :at => '5:02am' do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '2 5 * * 1-5 blahblah', output\n  end\n\n  test \"weekday at a multiple diverse times, via an array\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every \"weekday\", :at => %w(5:02am 3:52pm) do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '2 5 * * 1-5 blahblah', output\n    assert_match '52 15 * * 1-5 blahblah', output\n  end\n\n  test \"weekday at a multiple diverse times, comma separated\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every \"weekday\", :at => '5:02am, 3:52pm' do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '2 5 * * 1-5 blahblah', output\n    assert_match '52 15 * * 1-5 blahblah', output\n  end\n\n  test \"weekday at a multiple aligned times\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every \"weekday\", :at => '5:02am, 3:02pm' do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '2 5,15 * * 1-5 blahblah', output\n  end\n\n  test \"various days at a various aligned times\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every \"mon,wed,fri\", :at => '5:02am, 3:02pm' do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '2 5,15 * * 1,3,5 blahblah', output\n  end\n\n  test \"various days at a various aligned times using a runner\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/your/path'\n      every \"mon,wed,fri\", :at => '5:02am, 3:02pm' do\n        runner \"Worker.perform_async(1.day.ago)\"\n      end\n    file\n\n    assert_match %(2 5,15 * * 1,3,5 cd /your/path && bundle exec script/runner -e production 'Worker.perform_async(1.day.ago)'), output\n  end\n\n  test \"various days at a various aligned times using a rake task\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/your/path'\n      every \"mon,wed,fri\", :at => '5:02am, 3:02pm' do\n        rake \"blah:blah\"\n      end\n    file\n\n    assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', output\n  end\n\n  test \"A command every 1.month at very diverse times\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do\n        command \"blahblah\"\n      end\n    file\n\n    # The 1.month commands\n    assert_match '2 5 1 * * blahblah', output\n    assert_match '22 14 17 * * blahblah', output\n    assert_match '33 3 3 * * blahblah', output\n\n    # The 1.day commands\n    assert_match '2 5 * * * blahblah', output\n    assert_match '22 14 * * * blahblah', output\n    assert_match '33 3 * * * blahblah', output\n  end\n\n  test \"Multiple commands output every :reboot\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every :reboot do\n        command \"command_1\"\n        command \"command_2\"\n      end\n    file\n\n    assert_match \"@reboot command_1\", output\n    assert_match \"@reboot command_2\", output\n  end\n\n  test \"Many different job types output every :day\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/your/path'\n      every :daily do\n        rake \"blah:blah\"\n        runner \"runner_1\"\n        command \"command_1\"\n        runner \"runner_2\"\n        command \"command_2\"\n      end\n    file\n\n    assert_match '@daily cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', output\n    assert_match %(@daily cd /your/path && bundle exec script/runner -e production 'runner_1'), output\n    assert_match '@daily command_1', output\n    assert_match %(@daily cd /your/path && bundle exec script/runner -e production 'runner_2'), output\n    assert_match '@daily command_2', output\n  end\n\n  test \"every 5 minutes but but starting at 1\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 5.minutes, :at => 1 do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '1,6,11,16,21,26,31,36,41,46,51,56 * * * * blahblah', output\n  end\n\n  test \"every 4 minutes but starting at 2\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 4.minutes, :at => 2 do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '2,6,10,14,18,22,26,30,34,38,42,46,50,54,58 * * * * blahblah', output\n  end\n\n  test \"every 3 minutes but starting at 7\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 3.minutes, :at => 7 do\n        command \"blahblah\"\n      end\n    file\n\n\n    assert_match '7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * * blahblah', output\n  end\n\n  test \"every 2 minutes but starting at 27\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.minutes, :at => 27 do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', output\n  end\n\n  test \"using raw cron syntax\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every '0 0 27,31 * *' do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '0 0 27,31 * * blahblah', output\n  end\n\n  test \"using custom Chronic configuration to specify time using 24 hour clock\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :chronic_options, :hours24 => true\n      every 1.day, :at => '03:00' do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '0 3 * * * blahblah', output\n  end\n\n  test \"using custom Chronic configuration to specify date using little endian preference\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :chronic_options, :endian_precedence => :little\n      every 1.month, :at => '02/03 10:15' do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '15 10 2 * * blahblah', output\n  end\n\n  test \"using custom Chronic configuration to specify time using 24 hour clock and date using little endian preference\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :chronic_options, :hours24 => true, :endian_precedence => :little\n      every 1.month, :at => '01/02 04:30' do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match '30 4 1 * * blahblah', output\n  end\nend\n"
  },
  {
    "path": "test/functional/output_default_defined_jobs_test.rb",
    "content": "require 'test_helper'\n\nclass OutputDefaultDefinedJobsTest < Whenever::TestCase\n\n  # command\n\n  test \"A plain command with the job template set to nil\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah$/, output)\n  end\n\n  test \"A plain command with no job template set\" do\n    output = Whenever.cron \\\n    <<-file\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ \\/bin\\/bash -l -c 'blahblah'$/, output)\n  end\n\n  test \"A plain command with a job_template using a normal parameter\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, \"/bin/bash -l -c 'cd :path && :job'\"\n      every 2.hours do\n        set :path, \"/tmp\"\n        command \"blahblah\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ \\/bin\\/bash -l -c 'cd \\/tmp \\&\\& blahblah'$/, output)\n  end\n\n  test \"A plain command that overrides the job_template set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, \"/bin/bash -l -c ':job'\"\n      every 2.hours do\n        command \"blahblah\", :job_template => \"/bin/sh -l -c ':job'\"\n      end\n    file\n\n\n    assert_match(/^.+ .+ .+ .+ \\/bin\\/sh -l -c 'blahblah'$/, output)\n    assert_no_match(/bash/, output)\n  end\n\n  test \"A plain command that overrides the job_template set using a parameter\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, \"/bin/bash -l -c 'cd :path && :job'\"\n      every 2.hours do\n        set :path, \"/tmp\"\n        command \"blahblah\", :job_template => \"/bin/sh -l -c 'cd :path && :job'\"\n      end\n    file\n\n\n    assert_match(/^.+ .+ .+ .+ \\/bin\\/sh -l -c 'cd \\/tmp && blahblah'$/, output)\n    assert_no_match(/bash/, output)\n  end\n\n  test \"A plain command that is conditional on default environent and path\" do\n    Whenever.expects(:path).at_least_once.returns('/what/you/want')\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      if environment == 'production' && path == '/what/you/want'\n        every 2.hours do\n          command \"blahblah\"\n        end\n      end\n    file\n\n    assert_match(/blahblah/, output)\n  end\n\n  # runner\n\n  test \"A runner with path set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/my/path'\n      every 2.hours do\n        runner 'blahblah'\n      end\n    file\n\n    assert_match two_hours + %( cd /my/path && bundle exec script/runner -e production 'blahblah'), output\n  end\n\n  test \"A runner that overrides the path set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/my/path'\n      every 2.hours do\n        runner \"blahblah\", :path => '/some/other/path'\n      end\n    file\n\n    assert_match two_hours + %( cd /some/other/path && bundle exec script/runner -e production 'blahblah'), output\n  end\n\n  test \"A runner for a non-bundler app\" do\n    Whenever.expects(:bundler?).returns(false)\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/my/path'\n      every 2.hours do\n        runner 'blahblah'\n      end\n    file\n\n    assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), output\n  end\n\n  test \"A runner for an app with bin/rails\" do\n    Whenever.expects(:path).at_least_once.returns('/my/path')\n    Whenever.expects(:bin_rails?).returns(true)\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        runner 'blahblah'\n      end\n    file\n\n    assert_match two_hours + %( cd /my/path && bin/rails runner -e production 'blahblah'), output\n  end\n\n  test \"A runner for an app with script/rails\" do\n    Whenever.expects(:path).at_least_once.returns('/my/path')\n    Whenever.expects(:script_rails?).returns(true)\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        runner 'blahblah'\n      end\n    file\n\n    assert_match two_hours + %( cd /my/path && script/rails runner -e production 'blahblah'), output\n  end\n\n  # rake\n\n  test \"A rake command with path set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/my/path'\n      every 2.hours do\n        rake \"blahblah\"\n      end\n    file\n\n    assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec rake blahblah --silent', output\n  end\n\n  test \"A rake command with arguments\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/my/path'\n      every 2.hours do\n        rake \"blahblah[foobar]\"\n      end\n    file\n\n    assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec rake blahblah[foobar] --silent', output\n  end\n\n  test \"A rake for a non-bundler app\" do\n    Whenever.expects(:path).at_least_once.returns('/my/path')\n    Whenever.expects(:bundler?).returns(false)\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        rake 'blahblah'\n      end\n    file\n\n    assert_match two_hours + ' cd /my/path && RAILS_ENV=production rake blahblah --silent', output\n  end\n\n  test \"A rake command that overrides the path set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/my/path'\n      every 2.hours do\n        rake \"blahblah\", :path => '/some/other/path'\n      end\n    file\n\n    assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production bundle exec rake blahblah --silent', output\n  end\n\n  test \"A rake command that uses the default environment variable when RAILS_ENV is set\" do\n    ENV.expects(:fetch).with(\"RAILS_ENV\", \"production\").returns(\"development\")\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/my/path'\n      every 2.hours do\n        rake \"blahblah\"\n      end\n    file\n\n    assert_match two_hours + ' cd /my/path && RAILS_ENV=development bundle exec rake blahblah --silent', output\n  end\n\n  test \"A rake command that sets the environment variable\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/my/path'\n      set :environment_variable, 'RAKE_ENV'\n      every 2.hours do\n        rake \"blahblah\"\n      end\n    file\n\n    assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec rake blahblah --silent', output\n  end\n\n  test \"A rake command that overrides the environment variable\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/my/path'\n      set :environment_variable, 'RAKE_ENV'\n      every 2.hours do\n        rake \"blahblah\", :environment_variable => 'SOME_ENV'\n      end\n    file\n\n    assert_match two_hours + ' cd /my/path && SOME_ENV=production bundle exec rake blahblah --silent', output\n  end\n\n    # script\n\n  test \"A script command with path set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :path, '/my/path'\n      every 2.hours do\n        script \"blahblah\"\n      end\n    file\n\n    assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec script/blahblah', output\n  end\n\n  test \"A script command for a non-bundler app\" do\n    Whenever.expects(:path).at_least_once.returns('/my/path')\n    Whenever.expects(:bundler?).returns(false)\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        script 'blahblah'\n      end\n    file\n\n    assert_match two_hours + ' cd /my/path && RAILS_ENV=production script/blahblah', output\n  end\n\n  test \"A script command that uses output\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :output, '/log/file'\n      set :path, '/my/path'\n      every 2.hours do\n        script \"blahblah\", :path => '/some/other/path'\n      end\n    file\n\n    assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production bundle exec script/blahblah >> /log/file 2>&1', output\n  end\n\n  test \"A script command that uses an environment variable\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :environment_variable, 'RAKE_ENV'\n      set :path, '/my/path'\n      every 2.hours do\n        script \"blahblah\"\n      end\n    file\n\n    assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec script/blahblah', output\n  end\nend\n"
  },
  {
    "path": "test/functional/output_defined_job_test.rb",
    "content": "require 'test_helper'\n\nclass OutputDefinedJobTest < Whenever::TestCase\n  test \"defined job with a :task\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      job_type :some_job, \"before :task after\"\n      every 2.hours do\n        some_job \"during\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ before during after$/, output)\n  end\n\n  test \"defined job with a :task and some options\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      job_type :some_job, \"before :task after :option1 :option2\"\n      every 2.hours do\n        some_job \"during\", :option1 => 'happy', :option2 => 'birthday'\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ before during after happy birthday$/, output)\n  end\n\n  test \"defined job with a :task and an option where the option is set globally\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      job_type :some_job, \"before :task after :option1\"\n      set :option1, 'happy'\n      every 2.hours do\n        some_job \"during\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ before during after happy$/, output)\n  end\n\n  test \"defined job with a :task and an option where the option is set globally and locally\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      job_type :some_job, \"before :task after :option1\"\n      set :option1, 'global'\n      every 2.hours do\n        some_job \"during\", :option1 => 'local'\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ before during after local$/, output)\n  end\n\n  test \"defined job with a :task and an option where the option is set globally and on the group\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      job_type :some_job, \"before :task after :option1\"\n      set :option1, 'global'\n      every 2.hours, :option1 => 'group' do\n        some_job \"during\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ before during after group$/, output)\n  end\n\n  test \"defined job with a :task and an option where the option is set globally, on the group, and locally\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      job_type :some_job, \"before :task after :option1\"\n      set :option1, 'global'\n      every 2.hours, :option1 => 'group' do\n        some_job \"during\", :option1 => 'local'\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ before during after local$/, output)\n  end\n\n  test \"defined job with a :task and an option that is not set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      job_type :some_job, \"before :task after :option1\"\n      every 2.hours do\n        some_job \"during\", :option2 => 'happy'\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ before during after :option1$/, output)\n  end\n\n  test \"defined job that uses a :path where none is explicitly set\" do\n    Whenever.stubs(:path).returns('/my/path')\n\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      job_type :some_job, \"cd :path && :task\"\n      every 2.hours do\n        some_job 'blahblah'\n      end\n    file\n\n    assert_match two_hours + %( cd /my/path && blahblah), output\n  end\nend\n"
  },
  {
    "path": "test/functional/output_description_test.rb",
    "content": "require 'test_helper'\n\nclass OutputDescriptionTest < Whenever::TestCase\n  test \"single line description\" do\n    output = Whenever.cron \\\n    <<-file\n      every \"weekday\", :description => \"A description\" do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match \"# A description\\n0 0 * * 1-5 /bin/bash -l -c 'blahblah'\\n\\n\", output\n  end\n\n  test \"multi line description\" do\n    output = Whenever.cron \\\n    <<-file\n      every \"weekday\", :description => \"A description\\nhas mulitple lines\" do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match \"# A description\\n# has mulitple lines\\n0 0 * * 1-5 /bin/bash -l -c 'blahblah'\\n\\n\", output\n  end\nend\n"
  },
  {
    "path": "test/functional/output_env_test.rb",
    "content": "require 'test_helper'\n\nclass OutputEnvTest < Whenever::TestCase\n  setup do\n    @output = Whenever.cron \\\n    <<-file\n      env :MYVAR, 'blah'\n      env 'MAILTO', \"someone@example.com\"\n      env :BLANKVAR, ''\n      env :NILVAR, nil\n    file\n  end\n\n  should \"output MYVAR environment variable\" do\n    assert_match \"MYVAR=blah\", @output\n  end\n\n  should \"output MAILTO environment variable\" do\n    assert_match \"MAILTO=someone@example.com\", @output\n  end\n\n  should \"output BLANKVAR environment variable\" do\n    assert_match \"BLANKVAR=\\\"\\\"\", @output\n  end\n\n  should \"output NILVAR environment variable\" do\n    assert_match \"NILVAR=\\\"\\\"\", @output\n  end\nend\n"
  },
  {
    "path": "test/functional/output_jobs_for_roles_test.rb",
    "content": "require 'test_helper'\n\nclass OutputJobsForRolesTest < Whenever::TestCase\n  test \"one role requested and specified on the job\" do\n    output = Whenever.cron :roles => [:role1], :string => \\\n    <<-file\n      every 2.hours, :roles => [:role1] do\n        command \"blahblah\"\n      end\n    file\n\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah'\\n\\n\", output\n  end\n\n  test \"one role requested but none specified on the job\" do\n    output = Whenever.cron :roles => [:role1], :string => \\\n    <<-file\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    # this should output the job because not specifying a role means \"all roles\"\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah'\\n\\n\", output\n  end\n\n  test \"no roles requested but one specified on the job\" do\n    output = Whenever.cron \\\n    <<-file\n      every 2.hours, :roles => [:role1] do\n        command \"blahblah\"\n      end\n    file\n\n    # this should output the job because not requesting roles means \"all roles\"\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah'\\n\\n\", output\n  end\n\n  test \"a different role requested than the one specified on the job\" do\n    output = Whenever.cron :roles => [:role1], :string => \\\n    <<-file\n      every 2.hours, :roles => [:role2] do\n        command \"blahblah\"\n      end\n    file\n\n    assert_equal \"\", output\n  end\n\n  test \"with 2 roles requested and a job defined for each\" do\n    output = Whenever.cron :roles => [:role1, :role2], :string => \\\n    <<-file\n      every 2.hours, :roles => [:role1] do\n        command \"role1_cmd\"\n      end\n\n      every :hour, :roles => [:role2] do\n        command \"role2_cmd\"\n      end\n    file\n\n    assert_match two_hours + \" /bin/bash -l -c 'role1_cmd'\", output\n    assert_match \"0 * * * * /bin/bash -l -c 'role2_cmd'\", output\n  end\nend\n"
  },
  {
    "path": "test/functional/output_jobs_with_mailto_test.rb",
    "content": "require 'test_helper'\n\nclass OutputJobsWithMailtoTest < Whenever::TestCase\n  test \"defined job with a mailto argument\" do\n    output = Whenever.cron \\\n    <<-file\n      every 2.hours do\n        command \"blahblah\", mailto: 'someone@example.com'\n      end\n    file\n\n    output_without_empty_line = lines_without_empty_line(output.lines)\n\n    assert_equal 'MAILTO=someone@example.com', output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah'\", output_without_empty_line.shift\n  end\n\n  test \"defined job with every method's block and a mailto argument\" do\n    output = Whenever.cron \\\n    <<-file\n      every 2.hours, mailto: 'someone@example.com' do\n        command \"blahblah\"\n      end\n    file\n\n    output_without_empty_line = lines_without_empty_line(output.lines)\n\n    assert_equal 'MAILTO=someone@example.com', output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah'\", output_without_empty_line.shift\n  end\n\n  test \"defined job which overrided mailto argument in the block\" do\n    output = Whenever.cron \\\n    <<-file\n      every 2.hours, mailto: 'of_the_block@example.com' do\n        command \"blahblah\", mailto: 'overrided_in_the_block@example.com'\n      end\n    file\n\n    output_without_empty_line = lines_without_empty_line(output.lines)\n\n    assert_equal 'MAILTO=overrided_in_the_block@example.com', output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah'\", output_without_empty_line.shift\n  end\n\n  test \"defined some jobs with various mailto argument\" do\n    output = Whenever.cron \\\n    <<-file\n      every 2.hours do\n        command \"blahblah\"\n      end\n\n      every 2.hours, mailto: 'john@example.com' do\n        command \"blahblah_of_john\"\n        command \"blahblah2_of_john\"\n      end\n\n      every 2.hours, mailto: 'sarah@example.com' do\n        command \"blahblah_of_sarah\"\n      end\n\n      every 2.hours do\n        command \"blahblah_of_martin\", mailto: 'martin@example.com'\n        command \"blahblah2_of_sarah\", mailto: 'sarah@example.com'\n      end\n\n      every 2.hours do\n        command \"blahblah2\"\n      end\n    file\n\n    output_without_empty_line = lines_without_empty_line(output.lines)\n\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah'\", output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah2'\", output_without_empty_line.shift\n\n    assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah_of_john'\", output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah2_of_john'\", output_without_empty_line.shift\n\n    assert_equal 'MAILTO=sarah@example.com', output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah_of_sarah'\", output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah2_of_sarah'\", output_without_empty_line.shift\n\n    assert_equal 'MAILTO=martin@example.com', output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah_of_martin'\", output_without_empty_line.shift\n  end\n\n  test \"defined some jobs with no mailto argument jobs and mailto argument jobs(no mailto jobs should be first line of cron output\" do\n    output = Whenever.cron \\\n    <<-file\n      every 2.hours, mailto: 'john@example.com' do\n        command \"blahblah_of_john\"\n        command \"blahblah2_of_john\"\n      end\n\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    output_without_empty_line = lines_without_empty_line(output.lines)\n\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah'\", output_without_empty_line.shift\n\n    assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah_of_john'\", output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah2_of_john'\", output_without_empty_line.shift\n  end\n\n  test \"defined some jobs with environment mailto define and various mailto argument\" do\n    output = Whenever.cron \\\n    <<-file\n      env 'MAILTO', 'default@example.com'\n\n      every 2.hours do\n        command \"blahblah\"\n      end\n\n      every 2.hours, mailto: 'sarah@example.com' do\n        command \"blahblah_by_sarah\"\n      end\n\n      every 2.hours do\n        command \"blahblah_by_john\", mailto: 'john@example.com'\n      end\n\n      every 2.hours do\n        command \"blahblah2\"\n      end\n    file\n\n    output_without_empty_line = lines_without_empty_line(output.lines)\n\n    assert_equal 'MAILTO=default@example.com', output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah'\", output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah2'\", output_without_empty_line.shift\n\n    assert_equal 'MAILTO=sarah@example.com', output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah_by_sarah'\", output_without_empty_line.shift\n\n    assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah_by_john'\", output_without_empty_line.shift\n  end\nend\n\nclass OutputJobsWithMailtoForRolesTest < Whenever::TestCase\n  test \"one role requested and specified on the job with mailto argument\" do\n    output = Whenever.cron roles: [:role1], :string => \\\n    <<-file\n      env 'MAILTO', 'default@example.com'\n\n      every 2.hours, :roles => [:role1] do\n        command \"blahblah\"\n      end\n\n      every 2.hours, mailto: 'sarah@example.com', :roles => [:role2] do\n        command \"blahblah_by_sarah\"\n      end\n    file\n\n    output_without_empty_line = lines_without_empty_line(output.lines)\n\n    assert_equal 'MAILTO=default@example.com', output_without_empty_line.shift\n    assert_equal two_hours + \" /bin/bash -l -c 'blahblah'\", output_without_empty_line.shift\n    assert_nil output_without_empty_line.shift\n  end\nend\n"
  },
  {
    "path": "test/functional/output_redirection_test.rb",
    "content": "require 'test_helper'\n\nclass OutputRedirectionTest < Whenever::TestCase\n  test \"command when the output is set to nil\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :output, nil\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah >> \\/dev\\/null 2>&1$/, output)\n  end\n\n\n  test \"command when the output is set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :output, 'logfile.log'\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah >> logfile.log 2>&1$/, output)\n  end\n\n  test \"command when the error and standard output is set by the command\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        command \"blahblah\", :output => {:standard => 'dev_null', :error => 'dev_err'}\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output)\n  end\n\n  test \"command when the output is set and the comand overrides it\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :output, 'logfile.log'\n      every 2.hours do\n        command \"blahblah\", :output => 'otherlog.log'\n      end\n    file\n\n    assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)\n    assert_match(/^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1$/, output)\n  end\n\n  test \"command when the output is set and the comand overrides with standard and error\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :output, 'logfile.log'\n      every 2.hours do\n        command \"blahblah\", :output => {:error => 'dev_err', :standard => 'dev_null' }\n      end\n    file\n\n    assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)\n    assert_match(/^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output)\n  end\n\n  test \"command when the output is set and the comand rejects it\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :output, 'logfile.log'\n      every 2.hours do\n        command \"blahblah\", :output => false\n      end\n    file\n\n    assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)\n    assert_match(/^.+ .+ .+ .+ blahblah$/, output)\n  end\n\n  test \"command when the output is set and is overridden by the :set option\" do\n    output = Whenever.cron :set => 'output=otherlog.log', :string => \\\n    <<-file\n      set :job_template, nil\n      set :output, 'logfile.log'\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)\n    assert_match(/^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1/, output)\n  end\n\n  test \"command when the error and standard output is set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :output, {:error => 'dev_err', :standard => 'dev_null' }\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output)\n  end\n\n  test \"command when error output is set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :output, {:error => 'dev_null'}\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah 2>> dev_null$/, output)\n  end\n\n  test \"command when the standard output is set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :output, {:standard => 'dev_out'}\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah >> dev_out$/, output)\n  end\n\n  test \"command when error output is set by the command\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        command \"blahblah\", :output => {:error => 'dev_err'}\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah 2>> dev_err$/, output)\n  end\n\n  test \"command when standard output is set by the command\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        command \"blahblah\", :output => {:standard => 'dev_out'}\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah >> dev_out$/, output)\n  end\n\n  test \"command when standard output is set to nil\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        command \"blahblah\", :output => {:standard => nil}\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah > \\/dev\\/null$/, output)\n  end\n\n  test \"command when standard error is set to nil\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        command \"blahblah\", :output => {:error => nil}\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah 2> \\/dev\\/null$/, output)\n  end\n\n  test \"command when standard output and standard error is set to nil\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        command \"blahblah\", :output => {:error => nil, :standard => nil}\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah > \\/dev\\/null 2>&1$/, output)\n  end\n\n  test \"command when standard output is set and standard error is set to nil\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        command \"blahblah\", :output => {:error => nil, :standard => 'my.log'}\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah >> my.log 2> \\/dev\\/null$/, output)\n  end\n\n  test \"command when standard output is nil and standard error is set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      every 2.hours do\n        command \"blahblah\", :output => {:error => 'my_error.log', :standard => nil}\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah >> \\/dev\\/null 2>> my_error.log$/, output)\n  end\n\n  test \"command when the deprecated :cron_log is set\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :cron_log, \"cron.log\"\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah >> cron.log 2>&1$/, output)\n  end\n\n\n  test \"a command when the standard output is set to a lambda\" do\n    output = Whenever.cron \\\n    <<-file\n      set :job_template, nil\n      set :output, lambda { \"2>&1 | logger -t whenever_cron\" }\n      every 2.hours do\n        command \"blahblah\"\n      end\n    file\n\n    assert_match(/^.+ .+ .+ .+ blahblah 2>&1 | logger -t whenever_cron$/, output)\n  end\nend\n"
  },
  {
    "path": "test/test_case.rb",
    "content": "module Whenever\n  require 'minitest/autorun'\n  begin\n    # 2.0.0\n    class TestCase < Minitest::Test; end\n  rescue NameError\n    # 1.9.3\n    class TestCase < Minitest::Unit::TestCase; end\n  end\n\n\n  class TestCase\n    class << self\n      def setup(&block)\n        define_method(:setup) do\n          super()\n          instance_eval(&block)\n        end\n      end\n\n      def test(name, &block)\n        define_method(\"test_#{name}\".to_sym, &block)\n      end\n      alias should test\n    end\n\n    def assert_no_match(regexp, string)\n      message = \"<#{regexp}> expected to not match\\n<#{string}>\"\n      assert regexp !~ string, message\n    end\n  end\nend\n"
  },
  {
    "path": "test/test_helper.rb",
    "content": "require 'whenever'\nrequire 'test_case'\nrequire 'mocha/minitest'\nbegin\n  require 'active_support/all'\nrescue LoadError\nend\n\nmodule Whenever::TestHelpers\n  protected\n    def new_job(options={})\n      Whenever::Job.new(options)\n    end\n\n    def parse_time(time = nil, task = nil, at = nil, options = {})\n      Whenever::Output::Cron.new(time, task, at, options).time_in_cron_syntax\n    end\n\n    def two_hours\n      \"0 0,2,4,6,8,10,12,14,16,18,20,22 * * *\"\n    end\n\n    def assert_months_and_days_and_hours_and_minutes_equals(expected, time, options = {})\n      cron = parse_time(Whenever.seconds(1, :year), 'some task', time, options)\n      minutes, hours, days, months = cron.split(' ')\n      assert_equal expected, [months, days, hours, minutes]\n    end\n\n    def assert_days_and_hours_and_minutes_equals(expected, time, options = {})\n      cron = parse_time(Whenever.seconds(2, :months), 'some task', time, options)\n      minutes, hours, days, _ = cron.split(' ')\n      assert_equal expected, [days, hours, minutes]\n    end\n\n    def assert_hours_and_minutes_equals(expected, time, options = {})\n      cron = parse_time(Whenever.seconds(2, :days), 'some task', time, options)\n      minutes, hours, _ = cron.split(' ')\n      assert_equal expected, [hours, minutes]\n    end\n\n    def assert_minutes_equals(expected, time, options = {})\n      cron = parse_time(Whenever.seconds(2, :hours), 'some task', time, options)\n      assert_equal expected, cron.split(' ')[0]\n    end\n\n    def lines_without_empty_line(lines)\n      lines.map { |line| line.chomp }.reject { |line| line.empty? }\n    end\nend\n\nWhenever::TestCase.send(:include, Whenever::TestHelpers)\n"
  },
  {
    "path": "test/unit/capistrano_support_test.rb",
    "content": "require 'test_helper'\nrequire 'whenever/capistrano/v2/support'\n\nclass CapistranoSupportTestSubject\n  include Whenever::CapistranoSupport\nend\n\nclass CapistranoTestCase < Whenever::TestCase\n  setup do\n    @capistrano = CapistranoSupportTestSubject.new\n    configuration = mock()\n    configuration.stubs(:load).yields(@capistrano)\n    Whenever::CapistranoSupport.load_into(configuration)\n  end\nend\n\nclass CapistranoSupportTest < CapistranoTestCase\n  should \"return fetch(:whenever_options) from #whenever_options\" do\n    @capistrano.expects(:fetch).with(:whenever_options)\n    @capistrano.whenever_options\n  end\n\n  should \"return whenever_options[:roles] as an array from #whenever_roles with one role\" do\n    @capistrano.stubs(:whenever_options).returns({:roles => :role1})\n    assert_equal [:role1], @capistrano.whenever_roles\n  end\n\n  should \"return an empty array from #whenever_roles with no defined roles\" do\n    @capistrano.stubs(:whenever_options).returns({})\n    assert_equal [], @capistrano.whenever_roles\n  end\n\n  should \"return the list of servers returned by find_servers from #whenever_servers\" do\n    @capistrano.stubs(:whenever_options).returns({})\n    @capistrano.stubs(:find_servers).returns([:server1, :server2])\n\n    assert_equal [:server1, :server2], @capistrano.whenever_servers\n  end\n\n  should \"#whenever_prepare_for_rollback: set path to previous_release if there is a previous release\" do\n    args = {}\n    @capistrano.stubs(:fetch).with(:previous_release).returns(\"/some/path/20121221010000\")\n    assert_equal({:path => \"/some/path/20121221010000\"}, @capistrano.whenever_prepare_for_rollback(args))\n  end\n\n  should \"#whenever_prepare_for_rollback: set path to release_path and flags to whenever_clear_flags if there is no previous release\" do\n    args = {}\n    @capistrano.stubs(:fetch).with(:previous_release).returns(nil)\n    @capistrano.stubs(:fetch).with(:release_path).returns(\"/some/path/20121221010000\")\n    @capistrano.stubs(:fetch).with(:whenever_clear_flags).returns(\"--clear-crontab whenever_identifier\")\n    assert_equal({:path => \"/some/path/20121221010000\", :flags => \"--clear-crontab whenever_identifier\"}, @capistrano.whenever_prepare_for_rollback(args))\n  end\n\n  should \"#whenever_run_commands: require :command arg\" do\n    assert_raises ArgumentError do\n      @capistrano.whenever_run_commands(:options => {}, :path => {}, :flags => {})\n    end\n  end\n\n  should \"#whenever_run_commands: require :path arg\" do\n    assert_raises ArgumentError do\n      @capistrano.whenever_run_commands(:options => {}, :command => {}, :flags => {})\n    end\n  end\n\n  should \"#whenever_run_commands: require :flags arg\" do\n    assert_raises ArgumentError do\n      @capistrano.whenever_run_commands(:options => {}, :path => {}, :command => {})\n    end\n  end\nend\n\nclass ServerRolesTest < CapistranoTestCase\n  setup do\n    @mock_servers = [\"foo\", \"bar\"]\n    @capistrano.stubs(:whenever_servers).returns(@mock_servers)\n\n    @mock_server1, @mock_server2, @mock_server3 = mock(\"Server1\"), mock(\"Server2\"), mock(\"Server3\")\n    @mock_server1.stubs(:host).returns(\"server1.foo.com\")\n    @mock_server2.stubs(:host).returns(\"server2.foo.com\")\n    @mock_server3.stubs(:host => \"server3.foo.com\", :port => 1022, :user => 'test')\n    @mock_servers = [@mock_server1, @mock_server2]\n  end\n\n  should \"return a map of servers to their role(s)\" do\n    @capistrano.stubs(:whenever_roles).returns([:role1, :role2])\n    @capistrano.stubs(:role_names_for_host).with(\"foo\").returns([:role1])\n    @capistrano.stubs(:role_names_for_host).with(\"bar\").returns([:role2])\n    assert_equal({\"foo\" => [:role1], \"bar\" => [:role2]}, @capistrano.whenever_server_roles)\n  end\n\n  should \"exclude non-requested roles\" do\n    @capistrano.stubs(:whenever_roles).returns([:role1, :role2])\n    @capistrano.stubs(:role_names_for_host).with(\"foo\").returns([:role1, :role3])\n    @capistrano.stubs(:role_names_for_host).with(\"bar\").returns([:role2])\n    assert_equal({\"foo\" => [:role1], \"bar\" => [:role2]}, @capistrano.whenever_server_roles)\n  end\n\n  should \"include all roles for servers w/ >1 when they're requested\" do\n    @capistrano.stubs(:whenever_roles).returns([:role1, :role2, :role3])\n    @capistrano.stubs(:role_names_for_host).with(\"foo\").returns([:role1, :role3])\n    @capistrano.stubs(:role_names_for_host).with(\"bar\").returns([:role2])\n    assert_equal({\"foo\" => [:role1, :role3], \"bar\" => [:role2]}, @capistrano.whenever_server_roles)\n  end\n\n  should \"call run for each host w/ appropriate role args\" do\n    @capistrano.stubs(:role_names_for_host).with(@mock_server1).returns([:role1])\n    @capistrano.stubs(:role_names_for_host).with(@mock_server2).returns([:role2])\n    @capistrano.stubs(:whenever_servers).returns(@mock_servers)\n    roles = [:role1, :role2]\n    @capistrano.stubs(:whenever_options).returns({:roles => roles})\n\n    @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1', {:roles => roles, :hosts => @mock_server1})\n    @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role2', {:roles => roles, :hosts => @mock_server2})\n\n    @capistrano.whenever_run_commands(:command => \"whenever\",\n                                      :path => \"/foo/bar\",\n                                      :flags => \"--flag1 --flag2\")\n  end\n\n  should \"call run w/ all role args for servers w/ >1 role\" do\n    @capistrano.stubs(:role_names_for_host).with(@mock_server1).returns([:role1, :role3])\n    @capistrano.stubs(:whenever_servers).returns([@mock_server1])\n    roles = [:role1, :role2, :role3]\n    @capistrano.stubs(:whenever_options).returns({:roles => roles})\n\n    @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1,role3', {:roles => roles, :hosts => @mock_server1})\n\n    @capistrano.whenever_run_commands(:command => \"whenever\",\n                                      :path => \"/foo/bar\",\n                                      :flags => \"--flag1 --flag2\")\n  end\n\n  should \"call run w/ proper server options (port, user)\" do\n    @capistrano.stubs(:role_names_for_host).with(@mock_server3).returns([:role3])\n    @capistrano.stubs(:whenever_servers).returns([@mock_server3])\n    @capistrano.stubs(:whenever_options).returns({:roles => [:role3]})\n\n    @capistrano.expects(:run).once.with do |command, options|\n      options[:hosts].user == \"test\" && options[:hosts].port == 1022\n    end\n\n    @capistrano.whenever_run_commands(:command => \"whenever\",\n                                      :path => \"/foo/bar\",\n                                      :flags => \"--flag1 --flag2\")\n  end\nend\n"
  },
  {
    "path": "test/unit/cron_test.rb",
    "content": "require 'test_helper'\n\nclass CronTest < Whenever::TestCase\n  should \"raise if less than 1 minute\" do\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(59, :seconds))\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(0, :minutes))\n    end\n  end\n\n  # For sanity, do some tests on straight cron-syntax strings\n  should \"parse correctly\" do\n    assert_equal '* * * * *', parse_time(Whenever.seconds(1, :minute))\n    assert_equal '0,5,10,15,20,25,30,35,40,45,50,55 * * * *', parse_time(Whenever.seconds(5, :minutes))\n    assert_equal '7,14,21,28,35,42,49,56 * * * *', parse_time(Whenever.seconds(7, :minutes))\n    assert_equal '0,30 * * * *', parse_time(Whenever.seconds(30, :minutes))\n    assert_equal '32 * * * *', parse_time(Whenever.seconds(32, :minutes))\n    assert '60 * * * *' != parse_time(Whenever.seconds(60, :minutes)) # 60 minutes bumps up into the hour range\n  end\n\n  # Test all minutes\n  (2..59).each do |num|\n    should \"parse correctly for #{num} minutes\" do\n      start = 0\n      start += num unless 60.modulo(num).zero?\n      minutes = (start..59).step(num).to_a\n\n      assert_equal \"#{minutes.join(',')} * * * *\", parse_time(Whenever.seconds(num, :minutes))\n    end\n  end\nend\n\nclass CronParseHoursTest < Whenever::TestCase\n  should \"parse correctly\" do\n    assert_equal '0 * * * *', parse_time(Whenever.seconds(1, :hour))\n    assert_equal '0 0,2,4,6,8,10,12,14,16,18,20,22 * * *', parse_time(Whenever.seconds(2, :hours))\n    assert_equal '0 0,3,6,9,12,15,18,21 * * *', parse_time(Whenever.seconds(3, :hours))\n    assert_equal '0 5,10,15,20 * * *', parse_time(Whenever.seconds(5, :hours))\n    assert_equal '0 17 * * *', parse_time(Whenever.seconds(17, :hours))\n    assert '0 24 * * *' != parse_time(Whenever.seconds(24, :hours)) # 24 hours bumps up into the day range\n  end\n\n  (2..23).each do |num|\n    should \"parse correctly for #{num} hours\" do\n      start = 0\n      start += num unless 24.modulo(num).zero?\n      hours = (start..23).step(num).to_a\n\n      assert_equal \"0 #{hours.join(',')} * * *\", parse_time(Whenever.seconds(num, :hours))\n    end\n  end\n\n  should \"parse correctly when given an 'at' with minutes as an Integer\" do\n    assert_minutes_equals \"1\",  1\n    assert_minutes_equals \"14\", 14\n    assert_minutes_equals \"27\", 27\n    assert_minutes_equals \"55\", 55\n  end\n\n  should \"parse correctly when given an 'at' with minutes as a Time\" do\n    # Basically just testing that Chronic parses some times and we get the minutes out of it\n    assert_minutes_equals \"1\",  '3:01am'\n    assert_minutes_equals \"1\",  'January 21 2:01 PM'\n    assert_minutes_equals \"0\",  'midnight'\n    assert_minutes_equals \"59\", '13:59'\n  end\n\n  should \"parse correctly when given an 'at' with minutes as a Time and custom Chronic options are set\" do\n    assert_minutes_equals \"15\", '3:15'\n    assert_minutes_equals \"15\", '3:15', :chronic_options => { :hours24 => true }\n    assert_minutes_equals \"15\", '3:15', :chronic_options => { :hours24 => false }\n\n    assert_minutes_equals \"30\", '6:30'\n    assert_minutes_equals \"30\", '6:30', :chronic_options => { :hours24 => true }\n    assert_minutes_equals \"30\", '6:30', :chronic_options => { :hours24 => false }\n  end\n\n  should \"parse correctly when given an 'at' with minutes as a Range\" do\n    assert_minutes_equals \"15-30\", 15..30\n  end\n\n  should \"raise an exception when given an 'at' with an invalid minute value\" do\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :hour), nil, 60)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :hour), nil, -1)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :hour), nil, 0..60)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :hour), nil, -1..59)\n    end\n  end\nend\n\nclass CronParseDaysTest < Whenever::TestCase\n  should \"parse correctly\" do\n    assert_equal '0 0 * * *', parse_time(Whenever.seconds(1, :days))\n    assert_equal '0 0 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * *', parse_time(Whenever.seconds(2, :days))\n    assert_equal '0 0 1,5,9,13,17,21,25,29 * *', parse_time(Whenever.seconds(4, :days))\n    assert_equal '0 0 1,8,15,22 * *', parse_time(Whenever.seconds(7, :days))\n    assert_equal '0 0 1,17 * *', parse_time(Whenever.seconds(16, :days))\n    assert_equal '0 0 17 * *', parse_time(Whenever.seconds(17, :days))\n    assert_equal '0 0 29 * *', parse_time(Whenever.seconds(29, :days))\n    assert '0 0 30 * *' != parse_time(Whenever.seconds(30, :days)) # 30 days bumps into the month range\n  end\n\n  should \"parse correctly when given an 'at' with hours, minutes as a Time\" do\n    # first param is an array with [hours, minutes]\n    assert_hours_and_minutes_equals %w(3 45),  '3:45am'\n    assert_hours_and_minutes_equals %w(20 1),  '8:01pm'\n    assert_hours_and_minutes_equals %w(0 0),   'midnight'\n    assert_hours_and_minutes_equals %w(1 23),  '1:23 AM'\n    assert_hours_and_minutes_equals %w(23 59), 'March 21 11:59 pM'\n  end\n\n  should \"parse correctly when given an 'at' with hours, minutes as a Time and custom Chronic options are set\" do\n    # first param is an array with [hours, minutes]\n    assert_hours_and_minutes_equals %w(15 15), '3:15'\n    assert_hours_and_minutes_equals %w(3 15),  '3:15', :chronic_options => { :hours24 => true }\n    assert_hours_and_minutes_equals %w(15 15), '3:15', :chronic_options => { :hours24 => false }\n\n    assert_hours_and_minutes_equals %w(6 30),  '6:30'\n    assert_hours_and_minutes_equals %w(6 30),  '6:30', :chronic_options => { :hours24 => true }\n    assert_hours_and_minutes_equals %w(6 30),  '6:30', :chronic_options => { :hours24 => false }\n  end\n\n  should \"parse correctly when given an 'at' with hours as an Integer\" do\n    # first param is an array with [hours, minutes]\n    assert_hours_and_minutes_equals %w(1 0),  1\n    assert_hours_and_minutes_equals %w(3 0),  3\n    assert_hours_and_minutes_equals %w(15 0), 15\n    assert_hours_and_minutes_equals %w(19 0), 19\n    assert_hours_and_minutes_equals %w(23 0), 23\n  end\n\n  should \"parse correctly when given an 'at' with hours as a Range\" do\n    assert_hours_and_minutes_equals %w(3-23 0), 3..23\n  end\n\n  should \"raise an exception when given an 'at' with an invalid hour value\" do\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :day), nil, 24)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :day), nil, -1)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :day), nil, 0..24)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :day), nil, -1..23)\n    end\n  end\nend\n\nclass CronParseMonthsTest < Whenever::TestCase\n  should \"parse correctly\" do\n    assert_equal '0 0 1 * *', parse_time(Whenever.seconds(1, :month))\n    assert_equal '0 0 1 1,3,5,7,9,11 *', parse_time(Whenever.seconds(2, :months))\n    assert_equal '0 0 1 1,4,7,10 *', parse_time(Whenever.seconds(3, :months))\n    assert_equal '0 0 1 1,5,9 *', parse_time(Whenever.seconds(4, :months))\n    assert_equal '0 0 1 1,6 *', parse_time(Whenever.seconds(5, :months))\n    assert_equal '0 0 1 7 *', parse_time(Whenever.seconds(7, :months))\n    assert_equal '0 0 1 8 *', parse_time(Whenever.seconds(8, :months))\n    assert_equal '0 0 1 9 *', parse_time(Whenever.seconds(9, :months))\n    assert_equal '0 0 1 10 *', parse_time(Whenever.seconds(10, :months))\n    assert_equal '0 0 1 11 *', parse_time(Whenever.seconds(11, :months))\n    assert_equal '0 0 1 12 *', parse_time(Whenever.seconds(12, :months))\n  end\n\n  should \"parse months with a date and/or time\" do\n    # should set the day to 1 if no date is given\n    assert_equal '0 17 1 * *', parse_time(Whenever.seconds(1, :month), nil, \"5pm\")\n    # should use the date if one is given\n    assert_equal '0 2 23 * *', parse_time(Whenever.seconds(1, :month), nil, \"February 23rd at 2am\")\n    # should use an iteger as the day\n    assert_equal '0 0 5 * *', parse_time(Whenever.seconds(1, :month), nil, 5)\n  end\n\n  should \"parse correctly when given an 'at' with days, hours, minutes as a Time\" do\n    # first param is an array with [days, hours, minutes]\n    assert_days_and_hours_and_minutes_equals %w(1 3 45),  'January 1st 3:45am'\n    assert_days_and_hours_and_minutes_equals %w(11 23 0), 'Feb 11 11PM'\n    assert_days_and_hours_and_minutes_equals %w(22 1 1), 'march 22nd at 1:01 am'\n    assert_days_and_hours_and_minutes_equals %w(23 0 0), 'march 22nd at midnight' # looks like midnight means the next day\n  end\n\n  should \"parse correctly when given an 'at' with days, hours, minutes as a Time and custom Chronic options are set\" do\n    # first param is an array with [days, hours, minutes]\n    assert_days_and_hours_and_minutes_equals %w(22 15 45), 'February 22nd 3:45'\n    assert_days_and_hours_and_minutes_equals %w(22 15 45), '02/22 3:45'\n    assert_days_and_hours_and_minutes_equals %w(22 3 45),  'February 22nd 3:45', :chronic_options => { :hours24 => true }\n    assert_days_and_hours_and_minutes_equals %w(22 15 45), 'February 22nd 3:45', :chronic_options => { :hours24 => false }\n\n    assert_days_and_hours_and_minutes_equals %w(3 8 15), '02/03 8:15'\n    assert_days_and_hours_and_minutes_equals %w(3 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :middle }\n    assert_days_and_hours_and_minutes_equals %w(2 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :little }\n\n    assert_days_and_hours_and_minutes_equals %w(4 4 50),  '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => true }\n    assert_days_and_hours_and_minutes_equals %w(4 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => false }\n    assert_days_and_hours_and_minutes_equals %w(3 4 50),  '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => true }\n    assert_days_and_hours_and_minutes_equals %w(3 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => false }\n  end\n\n  should \"parse correctly when given an 'at' with days as an Integer\" do\n    # first param is an array with [days, hours, minutes]\n    assert_days_and_hours_and_minutes_equals %w(1 0 0),  1\n    assert_days_and_hours_and_minutes_equals %w(15 0 0), 15\n    assert_days_and_hours_and_minutes_equals %w(29 0 0), 29\n  end\n\n  should \"parse correctly when given an 'at' with days as a Range\" do\n    assert_days_and_hours_and_minutes_equals %w(1-7 0 0), 1..7\n  end\n\n  should \"raise an exception when given an 'at' with an invalid day value\" do\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :month), nil, 32)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :month), nil, -1)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :month), nil, 0..30)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :month), nil, 1..32)\n    end\n  end\nend\n\nclass CronParseYearTest < Whenever::TestCase\n  should \"parse correctly\" do\n    assert_equal '0 0 1 1 *', parse_time(Whenever.seconds(1, :year))\n  end\n\n  should \"parse year with a date and/or time\" do\n    # should set the day and month to 1 if no date is given\n    assert_equal '0 17 1 1 *', parse_time(Whenever.seconds(1, :year), nil, \"5pm\")\n    # should use the date if one is given\n    assert_equal '0 2 23 2 *', parse_time(Whenever.seconds(1, :year), nil, \"February 23rd at 2am\")\n    # should use an iteger as the month\n    assert_equal '0 0 1 5 *', parse_time(Whenever.seconds(1, :year), nil, 5)\n  end\n\n  should \"parse correctly when given an 'at' with days, hours, minutes as a Time\" do\n    # first param is an array with [months, days, hours, minutes]\n    assert_months_and_days_and_hours_and_minutes_equals %w(1 1 3 45),  'January 1st 3:45am'\n    assert_months_and_days_and_hours_and_minutes_equals %w(2 11 23 0), 'Feb 11 11PM'\n    assert_months_and_days_and_hours_and_minutes_equals %w(3 22 1 1),  'march 22nd at 1:01 am'\n    assert_months_and_days_and_hours_and_minutes_equals %w(3 23 0 0),  'march 22nd at midnight' # looks like midnight means the next day\n  end\n\n  should \"parse correctly when given an 'at' with days, hours, minutes as a Time and custom Chronic options are set\" do\n    # first param is an array with [months, days, hours, minutes]\n    assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), 'February 22nd 3:45'\n    assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), '02/22 3:45'\n    assert_months_and_days_and_hours_and_minutes_equals %w(2 22 3 45),  'February 22nd 3:45', :chronic_options => { :hours24 => true }\n    assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), 'February 22nd 3:45', :chronic_options => { :hours24 => false }\n\n    assert_months_and_days_and_hours_and_minutes_equals %w(2 3 8 15), '02/03 8:15'\n    assert_months_and_days_and_hours_and_minutes_equals %w(2 3 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :middle }\n    assert_months_and_days_and_hours_and_minutes_equals %w(3 2 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :little }\n\n    assert_months_and_days_and_hours_and_minutes_equals %w(3 4 4 50),  '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => true }\n    assert_months_and_days_and_hours_and_minutes_equals %w(3 4 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => false }\n    assert_months_and_days_and_hours_and_minutes_equals %w(4 3 4 50),  '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => true }\n    assert_months_and_days_and_hours_and_minutes_equals %w(4 3 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => false }\n  end\n\n  should \"parse correctly when given an 'at' with month as an Integer\" do\n    # first param is an array with [months, days, hours, minutes]\n    assert_months_and_days_and_hours_and_minutes_equals %w(1 1 0 0),  1\n    assert_months_and_days_and_hours_and_minutes_equals %w(5 1 0 0),  5\n    assert_months_and_days_and_hours_and_minutes_equals %w(12 1 0 0), 12\n  end\n\n  should \"parse correctly when given an 'at' with month as a Range\" do\n    assert_months_and_days_and_hours_and_minutes_equals %w(1-3 1 0 0), 1..3\n  end\n\n  should \"raise an exception when given an 'at' with an invalid month value\" do\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :year), nil, 13)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :year), nil, -1)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :year), nil, 0..12)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(Whenever.seconds(1, :year), nil, 1..13)\n    end\n  end\nend\n\nclass CronParseDaysOfWeekTest < Whenever::TestCase\n  should \"parse days of the week correctly\" do\n    {\n      '0' => %w(sun Sunday SUNDAY SUN),\n      '1' => %w(mon Monday MONDAY MON),\n      '2' => %w(tue tues Tuesday TUESDAY TUE),\n      '3' => %w(wed Wednesday WEDNESDAY WED),\n      '4' => %w(thu thurs thur Thursday THURSDAY THU),\n      '5' => %w(fri Friday FRIDAY FRI),\n      '6' => %w(sat Saturday SATURDAY SAT)\n    }.each do |day, day_tests|\n      day_tests.each do |day_test|\n        assert_equal \"0 0 * * #{day}\", parse_time(day_test)\n      end\n    end\n  end\n\n  should \"allow additional directives\" do\n    assert_equal '30 13 * * 5', parse_time('friday', nil, \"1:30 pm\")\n    assert_equal '22 2 * * 1', parse_time('Monday', nil, \"2:22am\")\n    assert_equal '55 17 * * 4', parse_time('THU', nil, \"5:55PM\")\n  end\n\n  should \"parse weekday correctly\" do\n    assert_equal '0 0 * * 1-5', parse_time('weekday')\n    assert_equal '0 0 * * 1-5', parse_time('Weekdays')\n    assert_equal '0 1 * * 1-5', parse_time('Weekdays', nil, \"1:00 am\")\n    assert_equal '59 5 * * 1-5', parse_time('Weekdays', nil, \"5:59 am\")\n  end\n\n  should \"parse weekend correctly\" do\n    assert_equal '0 0 * * 6,0', parse_time('weekend')\n    assert_equal '0 0 * * 6,0', parse_time('Weekends')\n    assert_equal '0 7 * * 6,0', parse_time('Weekends', nil, \"7am\")\n    assert_equal '2 18 * * 6,0', parse_time('Weekends', nil, \"6:02PM\")\n  end\nend\n\nclass CronParseShortcutsTest < Whenever::TestCase\n  should \"parse a :symbol into the correct shortcut\" do\n    assert_equal '@reboot',   parse_time(:reboot)\n    assert_equal '@annually', parse_time(:annually)\n    assert_equal '@yearly',   parse_time(:yearly)\n    assert_equal '@daily',    parse_time(:daily)\n    assert_equal '@midnight', parse_time(:midnight)\n    assert_equal '@monthly',  parse_time(:monthly)\n    assert_equal '@weekly',   parse_time(:weekly)\n    assert_equal '@hourly',   parse_time(:hourly)\n  end\n\n  should \"convert time-based shortcuts to times\" do\n    assert_equal '0 0 1 * *', parse_time(:month)\n    assert_equal '0 0 * * *', parse_time(:day)\n    assert_equal '0 * * * *', parse_time(:hour)\n    assert_equal '0 0 1 1 *', parse_time(:year)\n    assert_equal '0 0 1,8,15,22 * *', parse_time(:week)\n  end\n\n  should \"raise an exception if a valid shortcut is given but also an :at\" do\n    assert_raises ArgumentError do\n      parse_time(:hourly, nil, \"1:00 am\")\n    end\n\n    assert_raises ArgumentError do\n      parse_time(:reboot, nil, 5)\n    end\n\n    assert_raises ArgumentError do\n      parse_time(:daily, nil, '4:20pm')\n    end\n  end\nend\n\nclass CronParseRubyTimeTest < Whenever::TestCase\n  should \"process things like `1.day` correctly\" do\n    assert_equal \"0 0 * * *\", parse_time(1.day)\n  end\nend\n\nclass CronParseRawTest < Whenever::TestCase\n  should \"raise if cron-syntax string is too long\" do\n    assert_raises ArgumentError do\n      parse_time('* * * * * *')\n    end\n  end\n\n  should \"raise if cron-syntax string is invalid\" do\n    assert_raises ArgumentError do\n      parse_time('** * * * *')\n    end\n  end\n\n  should \"return the same cron sytax\" do\n    crons = ['0 0 27-31 * *', '* * * * *', '2/3 1,9,22 11-26 1-6 *', '*/5 6-23 * * *',\n             \"*\\t*\\t*\\t*\\t*\",\n             '7 17 * * FRI', '7 17 * * Mon-Fri', '30 12 * Jun *', '30 12 * Jun-Aug *',\n             '@reboot', '@yearly', '@annually', '@monthly', '@weekly',\n             '@daily', '@midnight', '@hourly']\n    crons.each do |cron|\n      assert_equal cron, parse_time(cron)\n    end\n  end\nend\n"
  },
  {
    "path": "test/unit/executable_test.rb",
    "content": "require 'test_helper'\n\ndescribe 'Executable' do\n  describe 'bin/wheneverize' do\n    describe 'ARGV is not empty' do\n      describe 'file does not exist' do\n        file = '/tmp/this_does_not_exist'\n\n        it 'prints STDERR' do\n          out, err = capture_subprocess_io do\n            system('wheneverize', file)\n          end\n\n          assert_empty(out)\n          assert_match(/`#{file}' does not exist./, err)\n        end\n      end\n\n      describe 'file exists, but not a directory' do\n        file = '/tmp/this_is_a_file.txt'\n        before { FileUtils.touch(file) }\n\n        it 'prints STDERR' do\n          begin\n            out, err = capture_subprocess_io do\n              system('wheneverize', file)\n            end\n\n            assert_empty(out)\n            assert_match(/`#{file}' is not a directory./, err)\n          ensure\n            FileUtils.rm(file)\n          end\n        end\n      end\n\n      describe 'file is a directory, but another param(s) are given as well' do\n        file = '/tmp/this_is_a_directory'\n        before { FileUtils.mkdir(file) }\n\n        it 'prints STDERR' do\n          begin\n            out, err = capture_subprocess_io do\n              system('wheneverize', file, 'another', 'parameters')\n            end\n\n            assert_empty(out)\n            assert_match(/#{\"Too many arguments; please specify only the \" \\\n                         \"directory to wheneverize.\"}/, err)\n          ensure\n            FileUtils.rmdir(file)\n          end\n        end\n      end\n    end\n\n    describe 'ARGV is empty' do\n      dir  = '.'\n      file = 'config/schedule.rb'\n      path = File.join(dir, file)\n\n      describe 'config file already exists' do\n        before do\n          FileUtils.mkdir(File.dirname(path))\n          FileUtils.touch(path)\n        end\n\n        it 'prints STDOUT and STDERR' do\n          begin\n            out, err = capture_subprocess_io do\n              system('wheneverize')\n            end\n\n            assert_match(/\\[done\\] wheneverized!/, out)\n            assert_match(/\\[skip\\] `#{path}' already exists/, err)\n          ensure\n            FileUtils.rm_rf(File.dirname(path))\n          end\n        end\n      end\n\n      describe 'config directory does not exist' do\n        it 'prints STDOUT and STDERR' do\n          begin\n            out, err = capture_subprocess_io do\n              system('wheneverize')\n            end\n\n            assert_match(/\\[add\\] creating `#{File.dirname(path)}'\\n/, err)\n            assert_match(/\\[done\\] wheneverized!/, out)\n          ensure\n            FileUtils.rm_rf(File.dirname(path))\n          end\n        end\n      end\n\n      describe 'config directory exists, but file does not' do\n        before { FileUtils.mkdir(File.dirname(path)) }\n\n        it 'writes config file and prints STDOUT' do\n          begin\n            out, err = capture_subprocess_io do\n              system('wheneverize')\n            end\n\n            assert_empty(err)\n            assert_match(\n              /\\[add\\] writing `#{path}'\\n\\[done\\] wheneverized!/,\n              out\n            )\n\n            assert_match((<<-FILE\n# Use this file to easily define all of your cron jobs.\n#\n# It's helpful, but not entirely necessary to understand cron before proceeding.\n# http://en.wikipedia.org/wiki/Cron\n\n# Example:\n#\n# set :output, \"/path/to/my/cron_log.log\"\n#\n# every 2.hours do\n#   command \"/usr/bin/some_great_command\"\n#   runner \"MyModel.some_method\"\n#   rake \"some:great:rake:task\"\n# end\n#\n# every 4.days do\n#   runner \"AnotherModel.prune_old_records\"\n# end\n\n# Learn more: http://github.com/javan/whenever\nFILE\n                         ), IO.read(path))\n          ensure\n            FileUtils.rm_rf(File.dirname(path))\n          end\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "test/unit/job_test.rb",
    "content": "require 'test_helper'\n\nclass JobTest < Whenever::TestCase\n  should \"return the :at set when #at is called\" do\n    assert_equal 'foo', new_job(:at => 'foo').at\n  end\n\n  should \"return the :roles set when #roles is called\" do\n    assert_equal ['foo', 'bar'], new_job(:roles => ['foo', 'bar']).roles\n  end\n\n  should \"return whether it has a role from #has_role?\" do\n    assert new_job(:roles => 'foo').has_role?('foo')\n    assert_equal false, new_job(:roles => 'bar').has_role?('foo')\n  end\n\n  should \"substitute the :task when #output is called\" do\n    job = new_job(:template => \":task\", :task => 'abc123')\n    assert_equal 'abc123', job.output\n  end\n\n  should \"substitute the :path when #output is called\" do\n    assert_equal 'foo', new_job(:template => ':path', :path => 'foo').output\n  end\n\n  should \"substitute the :path with the default Whenever.path if none is provided when #output is called\" do\n    Whenever.expects(:path).returns('/my/path')\n    assert_equal '/my/path', new_job(:template => ':path').output\n  end\n\n  should \"not substitute parameters for which no value is set\" do\n    assert_equal 'Hello :world', new_job(:template => ':matching :world', :matching => 'Hello').output\n  end\n\n  should \"escape the :path\" do\n    assert_equal '/my/spacey\\ path', new_job(:template => ':path', :path => '/my/spacey path').output\n  end\n\n  should \"escape percent signs\" do\n    job = new_job(\n      :template => \"before :foo after\",\n      :foo => \"percent -> % <- percent\"\n    )\n    assert_equal %q(before percent -> \\% <- percent after), job.output\n  end\n\n  should \"assume percent signs are not already escaped\" do\n    job = new_job(\n      :template => \"before :foo after\",\n      :foo => %q(percent preceded by a backslash -> \\% <-)\n    )\n    assert_equal %q(before percent preceded by a backslash -> \\\\\\% <- after), job.output\n  end\n\n  should \"squish spaces and newlines\" do\n    job = new_job(\n      :template => \"before :foo after\",\n      :foo => \"newline -> \\n <- newline space ->     <- space\"\n    )\n\n    assert_equal \"before newline -> <- newline space -> <- space after\", job.output\n  end\nend\n\n\nclass JobWithQuotesTest < Whenever::TestCase\n  should \"output the :task if it's in single quotes\" do\n    job = new_job(:template => \"':task'\", :task => 'abc123')\n    assert_equal %q('abc123'), job.output\n  end\n\n  should \"output the :task if it's in double quotes\" do\n    job = new_job(:template => '\":task\"', :task => 'abc123')\n    assert_equal %q(\"abc123\"), job.output\n  end\n\n  should \"output escaped single quotes in when it's wrapped in them\" do\n    job = new_job(\n      :template => \"before ':foo' after\",\n      :foo => \"quote -> ' <- quote\"\n    )\n    assert_equal %q(before 'quote -> '\\'' <- quote' after), job.output\n  end\n\n  should \"output escaped double quotes when it's wrapped in them\" do\n    job = new_job(\n      :template => 'before \":foo\" after',\n      :foo => 'quote -> \" <- quote'\n    )\n    assert_equal %q(before \"quote -> \\\" <- quote\" after), job.output\n  end\nend\n\nclass JobWithJobTemplateTest < Whenever::TestCase\n  should \"use the job template\" do\n    job = new_job(:template => ':task', :task => 'abc123', :job_template => 'left :job right')\n    assert_equal 'left abc123 right', job.output\n  end\n\n  should \"reuse parameter in the job template\" do\n    job = new_job(:template => ':path :task', :path => 'path', :task => \"abc123\", :job_template => ':path left :job right')\n    assert_equal 'path left path abc123 right', job.output\n  end\n\n  should \"escape single quotes\" do\n    job = new_job(:template => \"before ':task' after\", :task => \"quote -> ' <- quote\", :job_template => \"left ':job' right\")\n    assert_equal %q(left 'before '\\''quote -> '\\\\''\\\\'\\\\'''\\\\'' <- quote'\\'' after' right), job.output\n  end\n\n  should \"escape double quotes\" do\n    job = new_job(:template => 'before \":task\" after', :task => 'quote -> \" <- quote', :job_template => 'left \":job\" right')\n    assert_equal %q(left \"before \\\"quote -> \\\\\\\" <- quote\\\" after\" right), job.output\n  end\nend\n"
  },
  {
    "path": "whenever.gemspec",
    "content": "# frozen_string_literal: true\n\nrequire_relative \"lib/whenever/version\"\n\nGem::Specification.new do |spec|\n  spec.name        = \"whenever\"\n  spec.version     = Whenever::VERSION\n  spec.platform    = Gem::Platform::RUBY\n  spec.authors     = [\"Javan Makhmali\"]\n  spec.email       = [\"javan@javan.us\"]\n\n  spec.summary     = %q{Cron jobs in ruby.}\n  spec.description = %q{Clean ruby syntax for writing and deploying cron jobs.}\n  spec.homepage    = \"https://github.com/javan/whenever\"\n  spec.license     = \"MIT\"\n  spec.required_ruby_version = \">= 1.9.3\"\n\n  spec.metadata[\"homepage_uri\"] = spec.homepage\n  spec.metadata[\"source_code_uri\"] = \"https://github.com/javan/whenever\"\n  spec.metadata[\"changelog_uri\"] = \"https://github.com/javan/whenever/blob/main/CHANGELOG.md\"\n  spec.metadata[\"rubygems_mfa_required\"] = \"true\"\n\n  spec.files         = `git ls-files`.split(\"\\n\")\n  spec.test_files    = `git ls-files -- test/{functional,unit}/*`.split(\"\\n\")\n  spec.executables   = spec.files.grep(%r{\\Abin/}) { |f| File.basename(f) }\n  spec.require_paths = [\"lib\"]\n\n  spec.add_dependency \"chronic\", \">= 0.6.3\"\nend\n"
  }
]