Preserve whitespace at the end of crontab contents (issue #95)

This commit is contained in:
Rich Meyers 2010-11-01 17:07:09 -04:00
parent ca10a69e83
commit c4abbefe00
2 changed files with 7 additions and 5 deletions

View File

@ -106,7 +106,11 @@ module Whenever
end end
def prepare(contents) def prepare(contents)
contents.split("\n")[@options[:cut]..-1].join("\n") # Some cron implementations require all non-comment lines to be newline-terminated.
# Preserve any whitespace at the end of contents. (issue #95)
stripped_contents = contents.strip
tail = contents[stripped_contents.length..-1]
stripped_contents.split("\n")[@options[:cut]..-1].join("\n") + tail
end end
def comment_base def comment_base

View File

@ -281,8 +281,7 @@ My whenever job that was already here
# End Whenever generated tasks for: My identifier # End Whenever generated tasks for: My identifier
EXISTING_CRON EXISTING_CRON
# here-doc adds an extra newline we need removed assert_equal existing, @command.send(:prepare, existing)
assert_equal existing.strip, @command.send(:prepare, existing)
end end
should "trim off the top lines of the file" do should "trim off the top lines of the file" do
@ -302,8 +301,7 @@ My whenever job that was already here
# End Whenever generated tasks for: My identifier # End Whenever generated tasks for: My identifier
NEW_CRON NEW_CRON
# here-doc adds an extra newline we need removed assert_equal new_cron, @command.send(:prepare, existing)
assert_equal new_cron.strip, @command.send(:prepare, existing)
end end
end end