rspec / rspec-mocks

RSpec's 'test double' framework, with support for stubbing and mocking
https://rspec.info
MIT License
1.16k stars 357 forks source link

Keyword args not validated #1548

Closed eaden-hnry closed 1 year ago

eaden-hnry commented 1 year ago

With the following class,

class Foo
  def self.mymeth(arg1:, arg2:)
  end
end

The following test passes:

expect(Foo).to receive(:mymeth).with("hello").and_return(true)
Foo.mymeth("hello")

I have a couple of questions; Given that receive will validate that Foo actually has a method called mymeth, it seems some validation is taking place.

Should with also validate that the correct keyword arguments are passed?

If not, why should receive validate the method exists?

pirj commented 1 year ago

Are you certain you've turned on partial double verification on?

RSpec.configure do |config|
  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end
end