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

3.12.1, ruby 3.2, mocking keyword args via block, when verify_partial_doubles #1515

Closed jrochkind closed 1 year ago

jrochkind commented 1 year ago

I noticed #1508, released in rspec-mocks 3.12.1.

However, the problem still seems to be there in cases of rspec-mocks config verify_partial_doubles = true.

Below standalone example passes with ruby 3.1.3, fails with ruby 3.2.0. I expect it to pass with both.

(This is of course isolated into a reproduction case from an actual codebase with more going on)

In both cases rspec 3.12.0, rspec-mocks 3.12.1.

begin
  require "bundler/inline"
rescue LoadError => e
  $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
  raise e
end

gemfile(true) do
  source "https://rubygems.org"

  gem "rspec", "3.12.0" # Activate the gem and version you are reporting the issue against.
  gem "rspec-mocks", "3.12.1"
end

puts "Ruby version is: #{RUBY_VERSION}"
require 'rspec/autorun'

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

class MyClass
  def my_method(**options)
    puts options
  end
end

RSpec.describe 'allow to receive' do
  it 'can receive kw args in block' do
    obj = MyClass.new

    allow(obj).to receive(:my_method) do |**args|
      expect(args[:foo]).to eq "bar"
      "value"
    end

    obj.my_method(foo: "bar")
  end
end

Without mocks.verify_partial_doubles = true, passes in both ruby 3.1 and 3.2. I think the fix in #1508 is somehow ineffective in cases of mocks.verify_partial_doubles = true?

jrochkind commented 1 year ago

Nevermind, I think this is has already been reported, and I think fixed in #1514. Closing.

(it's hard to know how to describe this and recognize when it's a dup, but I think it is!)