rspec-expectations icon indicating copy to clipboard operation
rspec-expectations copied to clipboard

Composable matcher diffing

Open maxlinc opened this issue 11 years ago • 7 comments

The new composable matchers are awesome and I'm hoping to make use of them. I think it makes sense to format the expectations using the description rather than inspect, but the output (particularly diffable output) doesn't always make sense.

Consider the case of one missing object. The contain_exactly output is pretty good:

expect(['aa', 'bb', 'cc']).to contain_exactly(
  a_string_ending_with('a'),
  a_string_ending_with('b'),
  a_string_ending_with('c'),
  a_string_ending_with('d')
) #=>
# RSpec::Expectations::ExpectationNotMetError: expected collection contained:  [(a string ending with "a"), (a string ending with "b"), (a string ending with "c"), (a string ending with "d")]
# actual collection contained:    ["aa", "bb", "cc"]
# the missing elements were:      [(a string ending with "d")]

The include and match output doesn't make as much sense:

expect(['aa', 'bb', 'cc']).to include(
  a_string_ending_with('a'),
  a_string_ending_with('b'),
  a_string_ending_with('c'),
  a_string_ending_with('d')
) #=>
# RSpec::Expectations::ExpectationNotMetError: expected ["aa", "bb", "cc"] to match [(a string ending with "a"), (a string ending with "b"), (a string ending with "c"), (a string ending with "d")]
# Diff:
# @@ -1,5 +1,2 @@
# -[(a string ending with "a"),
# - (a string ending with "b"),
# - (a string ending with "c"),
# - (a string ending with "d")]
# +["aa", "bb", "cc"]

It's displaying a diff, but the diff didn't give me any information. It makes it look like all of my matchers failed, when really the problem is just the last one.

Hope the feedback helps. Thanks for the new features in rspec3 beta!

maxlinc avatar Mar 11 '14 16:03 maxlinc