I need to match long multiline strings (strings with \n embedded) while
ignoring whitespace and comments and more.
Writing a custom matcher for that was not much of a problem using the
Matcher DSL.
However, the Diff output I get does not work for me.
Diff treats the expected string as one long line, not splitting it at \n,
or so it seems.
I stripped my code to show the issue. Like this the custom matcher does not
make much sense anymore, but it demonstrates the issue in a single spec
file.
require 'rspec'
RSpec::Matchers.define :custom_match do |expected|
match do |actual|
actual == expected
end
diffable
end
describe 'the difference in output between #== and custom matcher using
#==' do
before(:all) do
@str1 = "line1\nline2\n"
@str2 = "LINE1\nline2\n"
end
# fail on purpose
it 'presents a diff per line' do
@str1.should == @str2
end
# OUTPUT:
# expected: "LINE1\nline2\n"
# got: "line1\nline2\n" (using ==)
# Diff:
# @@ -1,3 +1,3 @@
# -LINE1
# +line1
# line2
# fail on purpose
it 'presents a diff for the whole string' do
@str1.should custom_match(@str2)
end
# OUTPUT:
# expected "line1\nline2\n" to custom match "LINE1\nline2\n"
# Diff:
# @@ -1,2 +1,3 @@
# -LINE1\nline2\n
# +line1
# +line2
end
The Diff output in the first example is what I want.
The Diff output of the second example shows that the expected string is not
split as expected..
I have no clue how to make Diff produce output like in the first example.
Suggestions much appreciated.
Thanks
-jennek
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/f8d62416-b916-4130-9066-f64340c4af66%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.