Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSpec 3.11 mistakes kwargs for hash, when verify_partial_doubles is set to true #1549

Closed
64kramsystem opened this issue Jun 5, 2023 · 4 comments

Comments

@64kramsystem
Copy link
Contributor

64kramsystem commented Jun 5, 2023

Subject of the issue

When verify_partial_doubles is set to true, RSpec 3.11 reports some failures (on Ruby 3.2), mistaking kwargs for hashes; this does not happen on RSpec 3.12.

The kwargs/hashes problem is a known dev mistake (on Ruby 3.2), however, it seems not to be the cause here, because if this was the case, RSpec would report a failure on both 3.11 and 3.12; regardless, it should be unrelated to verify_partial_doubles.

The failure output is in this form:

        expected: ([foo, bar], {:baz=>qux})
            got: ([foo, bar], {:baz=>qux})

Your environment

  • Ruby version: 3.2.2
  • rspec-mocks version: 3.11.2

Steps to reproduce

There you go:

# frozen_string_literal: true

require "bundler/inline"

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

  gem "rspec", "3.11.0"
end

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

RSpec.configure do |config|
  config.mock_with :rspec do |mocks|
    #######################################################################
    # PROBLEM IS HERE; EXPECTATION FAILS WHEN THIS IS SET TO TRUE
    #######################################################################
    mocks.verify_partial_doubles = true
  end
end

class MyClass
  def start_service(myparam: nil)
  end

  def restart_service(myparam: nil)
    start_service(myparam: 'foo')
  end
end

describe MyClass do
  it 'should pass' do
    expect(subject).to receive(:start_service).with(myparam: 'foo')
    subject.restart_service(myparam: 'foo')
  end
end

Expected behavior

The expectation should be met.

Actual behavior

The expectation is not met, because the kwargs are mistaken for a hash.

@64kramsystem 64kramsystem changed the title RSpec 3.11 mistakes kwargs for hash, when verify_partial_doubles is set to tru RSpec 3.11 mistakes kwargs for hash, when verify_partial_doubles is set to true Jun 5, 2023
@pirj
Copy link
Member

pirj commented Jun 5, 2023

This is fixed by #1514, and released in 3.12.2. Please use a more recent version. I believe we don’t backport fixes to prior minor releases.

@pirj pirj closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2023
@JonRowe
Copy link
Member

JonRowe commented Jun 5, 2023

Apologies but as @pirj said we don't backport fixes to older minor versions, only maintaining the current major/minor release stream, you should be able to upgrade to 3.12 seamlessly as there are no breaking changes.

@64kramsystem
Copy link
Contributor Author

Thanks for looking 🙏.

(this is a PITA for us, because One Famous Gem™ (chef cough cough) transitively depends on rspec (!!!), worse, restricting the version to <= 3.11)

@pirj
Copy link
Member

pirj commented Jun 5, 2023

inspec/inspec#6523

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants