rspec/rspec-expectations — Issue #97: Add support for choosing differs
Author: dchelimsky
Created: 2011-11-24 15:29:19+00:00
State: open

We've had a few issues and pull requests dealing with diffing, but I think we need a more holistic solution. There are a growing number of diffing solutions out there now, each of which are going to appeal more to some people than others, so I think we should have a reasonable default behavior, but then expose an API for choosing your own differ. Something like:

```ruby
RSpec.configure do |c|
c.diff {|actual,expected| MyPreferredDefaultDiffer.diff(actual, expected)} # default
c.diff(Hash) {|expected,actual| MyPreferredHashDiffer.diff(expected, actual)}
c.diff(Array) {|expected,actual| MyPreferredArrayDiffer.diff(expected, actual)}
c.diff(String) {|expected,actual| MyPreferredStringDiffer.diff(expected, actual)}
# etc
end
```

The form with a single argument would invoke the supplied block if both expected and actual values match the argument, otherwise the default would be used.