Skip to content

Commit

Permalink
Squish whitespace instead of tripping on newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
javan committed Feb 9, 2014
1 parent 7593553 commit 9695d7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
9 changes: 3 additions & 6 deletions lib/whenever/job.rb
Expand Up @@ -17,11 +17,8 @@ def initialize(options = {})
end

def output
job = process_template(@template, @options).strip
out = process_template(@job_template, @options.merge(:job => job)).strip
if out =~ /\n/
raise ArgumentError, "Task contains newline"
end
job = process_template(@template, @options)
out = process_template(@job_template, @options.merge(:job => job))
out.gsub(/%/, '\%')
end

Expand All @@ -43,7 +40,7 @@ def process_template(template, options)
else
option
end
end
end.squish
end

def escape_single_quotes(str)
Expand Down
9 changes: 4 additions & 5 deletions test/unit/job_test.rb
Expand Up @@ -54,14 +54,13 @@ class JobTest < Test::Unit::TestCase
assert_equal %q(before percent preceded by a backslash -> \\\% <- after), job.output
end

should "reject newlines" do
should "squish spaces and newlines" do
job = new_job(
:template => "before :foo after",
:foo => "newline -> \n <- newline"
:foo => "newline -> \n <- newline space -> <- space"
)
assert_raise ArgumentError do
job.output
end

assert_equal "before newline -> <- newline space -> <- space after", job.output
end
end

Expand Down

0 comments on commit 9695d7d

Please sign in to comment.