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

When using keyword arguments in mock expectations and calling with a hash the diff is confusing

Open JonRowe opened this issue 4 years ago • 1 comments

When you call keyword argument methods with hashes (e.g. if a method_missing doesn't have a proper ruby2_keywords call or a keyword splat) then the diff is confusing because it looks identical. This is going to be tricky to solve because to the differ, they are both hashes...

Steps to reproduce

class SomeClass
  def method_name(value:)
  end
end

RSpec.describe "SomeClass" do
  it "receives keyword arguments" do
    klass = SomeClass.new
    expect(klass).to receive(:method_name).with(value: [1,2,3])
    klass.method_name({value: [1, 2, 3]})
  end
end

Possible/suggested behaviour

 #<SomeClass (class)> received :method_name with unexpected arguments
         expected: (value: [1, 2, 3])
              got: ({:value =>[1, 2, 3]})

Actual behaviour

 #<SomeClass (class)> received :method_name with unexpected arguments
         expected: ({:value => [1, 2, 3]})
              got: ({:value => [1, 2, 3]})

JonRowe avatar Aug 12 '21 21:08 JonRowe