diff --git a/lib/whenever/command_line.rb b/lib/whenever/command_line.rb index 92e2b0f..d89f64a 100644 --- a/lib/whenever/command_line.rb +++ b/lib/whenever/command_line.rb @@ -106,7 +106,11 @@ module Whenever end 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 def comment_base diff --git a/test/functional/command_line_test.rb b/test/functional/command_line_test.rb index 654d2c4..fe18400 100644 --- a/test/functional/command_line_test.rb +++ b/test/functional/command_line_test.rb @@ -281,8 +281,7 @@ My whenever job that was already here # End Whenever generated tasks for: My identifier EXISTING_CRON - # here-doc adds an extra newline we need removed - assert_equal existing.strip, @command.send(:prepare, existing) + assert_equal existing, @command.send(:prepare, existing) end 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 NEW_CRON - # here-doc adds an extra newline we need removed - assert_equal new_cron.strip, @command.send(:prepare, existing) + assert_equal new_cron, @command.send(:prepare, existing) end end