splitwise/super_diff

The have_attributes matcher doesn't show a diff

Closed this issue · 1 comments

The have_attributes matcher doesn't show a diff and is therefore less useful than the default RSpec output. Here's a simple code snippet that shows the issue:

Product = Data.define(:name, :price)

RSpec.describe "subject" do
  it "does something" do
    p1 = Product.new(name: "foo", price: 3)

    expect(p1).to have_attributes(name: "foo", price: 4)
  end
end

With RSpec's default output, this is the result:

$ rspec few_attributes_spec.rb                                                                                                                                                                                                                                                            
F

Failures:

  1) subject does something
     Failure/Error: expect(p1).to have_attributes(name: "foo", price: 4)

       expected #<data Product name="foo", price=3> to have attributes {:name => "foo", :price => 4} but had attributes {:name => "foo", :price => 3}
       Diff:
       @@ -1,3 +1,3 @@
        :name => "foo",
       -:price => 4,
       +:price => 3,

     # ./few_attributes_spec.rb:9:in `block (2 levels) in <top (required)>'

Finished in 0.01683 seconds (files took 0.08103 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./few_attributes_spec.rb:6 # subject does something

With SuperDiff enabled I get this output:

$ rspec few_attributes_spec.rb                                                                                                                                                                                                                                                             
F

Failures:

  1) subject does something
     Failure/Error: expect(p1).to have_attributes(name: "foo", price: 4)
       Expected #<data Product name: "foo", price: 3> to have attributes (name: "foo", price: 4).
     # /Users/jacobcarlborg/.rvm/gems/ruby-3.3.1/gems/super_diff-0.13.0/lib/super_diff/rspec/monkey_patches.rb:43:in `handle_failure'
     # ./few_attributes_spec.rb:9:in `block (2 levels) in <top (required)>'

Finished in 0.01356 seconds (files took 0.13665 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./few_attributes_spec.rb:6 # subject does something

Version information:

$ rspec --version                                                                                                                                                                                                                                                                         
RSpec 3.13
  - rspec-core 3.13.0
  - rspec-expectations 3.13.0
  - rspec-mocks 3.13.1
  - rspec-rails 6.1.2
  - rspec-support 3.13.1

$ bundle info super_diff                                                                                                                                                                                                                                                                   
  * super_diff (0.13.0)

Hi @jacob-carlborg-apoex, thanks for the report. I believe this is a duplicate of #250 – there was a change to RSpec 3.13.0 that breaks the have_attributes monkey patch. I've already opened a PR for it and will get to it soon. :)