Permalink
Browse files

Diff when comparing a multiline string to a regexp

- Closes #8.
  • Loading branch information...
1 parent e7303e9 commit 76434fa598b48f4b31176f1a7312aca58c0a6e53 @dchelimsky dchelimsky committed Sep 4, 2010
Showing with 31 additions and 2 deletions.
  1. +27 −0 features/expectations/diffing.feature
  2. +4 −2 lib/rspec/expectations/differ.rb
View
27 features/expectations/diffing.feature
@@ -33,6 +33,33 @@ Feature: diffing
# ./example_spec.rb:13
"""
+ Scenario: diff for a multiline string and a regexp
+ Given a file named "example_spec.rb" with:
+ """
+ describe "a multiline string" do
+ it "is like another string" do
+ expected = /expected/m
+ actual = <<-ACTUAL
+ this is the
+ actual
+ string
+ ACTUAL
+ actual.should =~ expected
+ end
+ end
+ """
+ When I run "rspec example_spec.rb"
+ Then the output should contain:
+ """
+ Diff:
+ @@ -1,2 +1,4 @@
+ -/expected/m
+ +this is the
+ + actual
+ + string
+ # ./example_spec.rb:9
+ """
+
Scenario: no diff for a single line strings
Given a file named "example_spec.rb" with:
"""
View
6 lib/rspec/expectations/differ.rb
@@ -41,8 +41,10 @@ def diff_as_string(data_new, data_old)
output << oldhunk.diff(format) << "\n"
end
- def diff_as_object(target,expected)
- diff_as_string(PP.pp(target,""), PP.pp(expected,""))
+ def diff_as_object(actual,expected)
+ actual = String === actual ? actual : PP.pp(actual,"")
+ expected = String === expected ? expected : PP.pp(expected,"")
+ diff_as_string(actual, expected)
end
protected

0 comments on commit 76434fa

Please sign in to comment.