Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

better fix for bug when diffing multiline strings

  • Loading branch information...
commit e4d8dcb6f32732534e15f39e3bd8da1baa77f07b 1 parent 2c23be3
David Chelimsky dchelimsky authored
6 lib/rspec/expectations/fail_with.rb
View
@@ -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)
12 spec/rspec/matchers/include_spec.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.