Diff from diffable custom matcher does not handle multiline string properly?

77 views
Skip to first unread message

jennek...@oce.com

unread,
Jan 10, 2014, 5:51:46 PM1/10/14
to rs...@googlegroups.com
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

Myron Marston

unread,
Jan 10, 2014, 5:55:37 PM1/10/14
to rs...@googlegroups.com
You may have hit on a bug.  Can you report it to rspec-expectations?

Spe@King... World

unread,
Jan 10, 2014, 10:46:56 PM1/10/14
to rs...@googlegroups.com
Please, in the google support I can not find the rigtht settings in order to unsubscrive me from this group. Can you help me or, better, unsubscrive me from this e-mai messaging (it fills as-like spamming)?


--
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 rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/a5201a65-cf3b-48ef-b01b-a45f87c6191f%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

jennek...@oce.com

unread,
Jan 11, 2014, 4:58:45 AM1/11/14
to rs...@googlegroups.com
Done.
Reply all
Reply to author
Forward
0 new messages