Permalink
Browse files

better fix for bug when diffing multiline strings

  • Loading branch information...
1 parent 2c23be3 commit e4d8dcb6f32732534e15f39e3bd8da1baa77f07b @dchelimsky dchelimsky committed Mar 17, 2012
Showing with 17 additions and 1 deletion.
  1. +5 −1 lib/rspec/expectations/fail_with.rb
  2. +12 −0 spec/rspec/matchers/include_spec.rb
@@ -22,7 +22,11 @@ def fail_with(message, expected=nil, actual=nil)
if actual && expected
if all_strings?(actual, expected)
if any_multiline_strings?(actual, expected)
- message << "\nDiff:" << differ.diff_as_string(actual, expected)
+ if Array === expected
+ message << "\nDiff:" << differ.diff_as_string(actual, expected.join(","))
+ else
+ message << "\nDiff:" << differ.diff_as_string(actual, expected)
+ end
end
elsif no_procs?(actual, expected) && no_numbers?(actual, expected)
message << "\nDiff:" << differ.diff_as_object(actual, expected)
@@ -16,6 +16,18 @@
"abc".should include("d")
}.should fail_matching("expected \"abc\" to include \"d\"")
end
+
+ it "includes a diff when actual is multiline" do
+ lambda {
+ "abc\ndef".should include("g")
+ }.should fail_matching("expected \"abc\\ndef\" to include \"g\"\nDiff")
+ end
+
+ it "includes a diff when actual is multiline and there are multiple expecteds" do
+ lambda {
+ "abc\ndef".should include("g", "h")
+ }.should fail_matching("expected \"abc\\ndef\" to include \"g\" and \"h\"\nDiff")
+ end
end
context "for an array target" do

0 comments on commit e4d8dcb

Please sign in to comment.