Merge branch 'new_line_after_closing_comment'
This commit is contained in:
commit
8d3b02861a
@ -40,7 +40,7 @@ module Whenever
|
||||
end
|
||||
|
||||
def whenever_cron
|
||||
@whenever_cron ||= [comment_open, Whenever.cron(@options), comment_close].join("\n")
|
||||
@whenever_cron ||= [comment_open, Whenever.cron(@options), comment_close].join("\n") + "\n"
|
||||
end
|
||||
|
||||
def read_crontab
|
||||
@ -86,7 +86,7 @@ module Whenever
|
||||
|
||||
# If an existing identier block is found, replace it with the new cron entries
|
||||
if read_crontab.index(comment_open) && read_crontab.index(comment_close)
|
||||
read_crontab.gsub(Regexp.new("#{comment_open}.+#{comment_close}", Regexp::MULTILINE), whenever_cron)
|
||||
read_crontab.gsub(Regexp.new("#{comment_open}.+#{comment_close}", Regexp::MULTILINE), whenever_cron.chomp)
|
||||
else # Otherwise, append the new cron entries after any existing ones
|
||||
[read_crontab, whenever_cron].join("\n\n")
|
||||
end
|
||||
|
@ -11,13 +11,13 @@ class CommandLineTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
should "output the cron job with identifier blocks" do
|
||||
output = <<-expected
|
||||
output = <<-EXPECTED
|
||||
# Begin Whenever generated tasks for: My identifier
|
||||
#{@task}
|
||||
# End Whenever generated tasks for: My identifier
|
||||
expected
|
||||
EXPECTED
|
||||
|
||||
assert_equal unindent(output).chomp, @command.send(:whenever_cron).chomp
|
||||
assert_equal output, @command.send(:whenever_cron)
|
||||
end
|
||||
|
||||
should "write the crontab when run" do
|
||||
@ -38,22 +38,22 @@ class CommandLineTest < Test::Unit::TestCase
|
||||
existing = '# Existing crontab'
|
||||
@command.expects(:read_crontab).at_least_once.returns(existing)
|
||||
|
||||
new_cron = <<-expected
|
||||
new_cron = <<-EXPECTED
|
||||
#{existing}
|
||||
|
||||
# Begin Whenever generated tasks for: My identifier
|
||||
#{@task}
|
||||
# End Whenever generated tasks for: My identifier
|
||||
expected
|
||||
EXPECTED
|
||||
|
||||
assert_equal unindent(new_cron).chomp, @command.send(:updated_crontab).chomp
|
||||
assert_equal new_cron, @command.send(:updated_crontab)
|
||||
|
||||
@command.expects(:write_crontab).with(unindent(new_cron)).returns(true)
|
||||
@command.expects(:write_crontab).with(new_cron).returns(true)
|
||||
assert @command.run
|
||||
end
|
||||
|
||||
should "replace an existing block if the identifier matches" do
|
||||
existing = <<-existing
|
||||
existing = <<-EXISTING_CRON
|
||||
# Something
|
||||
|
||||
# Begin Whenever generated tasks for: My identifier
|
||||
@ -63,10 +63,11 @@ class CommandLineTest < Test::Unit::TestCase
|
||||
# Begin Whenever generated tasks for: Other identifier
|
||||
This shouldn't get replaced
|
||||
# End Whenever generated tasks for: Other identifier
|
||||
existing
|
||||
@command.expects(:read_crontab).at_least_once.returns(unindent(existing))
|
||||
EXISTING_CRON
|
||||
|
||||
new_cron = <<-new_cron
|
||||
@command.expects(:read_crontab).at_least_once.returns(existing)
|
||||
|
||||
new_cron = <<-NEW_CRON
|
||||
# Something
|
||||
|
||||
# Begin Whenever generated tasks for: My identifier
|
||||
@ -76,11 +77,11 @@ class CommandLineTest < Test::Unit::TestCase
|
||||
# Begin Whenever generated tasks for: Other identifier
|
||||
This shouldn't get replaced
|
||||
# End Whenever generated tasks for: Other identifier
|
||||
new_cron
|
||||
NEW_CRON
|
||||
|
||||
assert_equal unindent(new_cron).chomp, @command.send(:updated_crontab).chomp
|
||||
assert_equal new_cron, @command.send(:updated_crontab)
|
||||
|
||||
@command.expects(:write_crontab).with(unindent(new_cron)).returns(true)
|
||||
@command.expects(:write_crontab).with(new_cron).returns(true)
|
||||
assert @command.run
|
||||
end
|
||||
end
|
||||
@ -97,11 +98,4 @@ class CommandLineTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unindent(string)
|
||||
indentation = string[/\A\s*/]
|
||||
string.strip.gsub(/^#{indentation}/, "")
|
||||
end
|
||||
|
||||
end
|
@ -1,36 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{whenever}
|
||||
s.version = "0.3.1"
|
||||
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = ["Javan Makhmali"]
|
||||
s.date = %q{2009-06-25}
|
||||
s.description = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.}
|
||||
s.email = %q{javan@javan.us}
|
||||
s.executables = ["whenever", "wheneverize"]
|
||||
s.extra_rdoc_files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/command_line.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/version.rb", "lib/whenever.rb", "README.rdoc"]
|
||||
s.files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/command_line.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/version.rb", "lib/whenever.rb", "Manifest", "Rakefile", "README.rdoc", "test/command_line_test.rb", "test/cron_test.rb", "test/output_command_test.rb", "test/output_env_test.rb", "test/output_rake_test.rb", "test/output_runner_test.rb", "test/test_helper.rb", "whenever.gemspec"]
|
||||
s.has_rdoc = true
|
||||
s.homepage = %q{http://github.com/javan/whenever}
|
||||
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whenever", "--main", "README.rdoc"]
|
||||
s.require_paths = ["lib"]
|
||||
s.rubyforge_project = %q{whenever}
|
||||
s.rubygems_version = %q{1.3.1}
|
||||
s.summary = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.}
|
||||
s.test_files = ["test/command_line_test.rb", "test/cron_test.rb", "test/output_command_test.rb", "test/output_env_test.rb", "test/output_rake_test.rb", "test/output_runner_test.rb", "test/test_helper.rb"]
|
||||
|
||||
if s.respond_to? :specification_version then
|
||||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
||||
s.specification_version = 2
|
||||
|
||||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
||||
s.add_runtime_dependency(%q<chronic>, [">= 0.2.3"])
|
||||
else
|
||||
s.add_dependency(%q<chronic>, [">= 0.2.3"])
|
||||
end
|
||||
else
|
||||
s.add_dependency(%q<chronic>, [">= 0.2.3"])
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user