Permalink
Browse files

Tracing nil objects is ok.

  • Loading branch information...
1 parent 3677a9b commit 3fb4d208def7181b8d5fa16a9b11b4a06d8cb682 @jimweirich committed Jan 23, 2013
Showing with 11 additions and 1 deletion.
  1. +4 −1 lib/rake/trace_output.rb
  2. +7 −0 test/test_trace_output.rb
View
@@ -11,7 +11,10 @@ def trace_on(out, *strings)
if strings.empty?
output = sep
else
- output = strings.map { |s| s.nil? || s.end_with?(sep) ? s : s + sep }.join
+ output = strings.map { |s|
+ next if s.nil?
+ s.end_with?(sep) ? s : s + sep
+ }.join
end
out.print(output)
end
@@ -30,6 +30,13 @@ def test_trace_issues_single_io_for_args_multiple_strings
assert_equal 1, spy.calls
end
+ def test_trace_handles_nil_objects
+ spy = PrintSpy.new
+ trace_on(spy, "HI\n", nil, "LO")
+ assert_equal "HI\nLO\n", spy.result
+ assert_equal 1, spy.calls
+ end
+
def test_trace_issues_single_io_for_args_multiple_strings_and_alternate_sep
old_sep = $\
$\ = "\r"

0 comments on commit 3fb4d20

Please sign in to comment.