rspec / rspec/rspec

3.11.1 breaks argument matching in Ruby 2.7

Open
#68 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
117
Forks
51
Avg merge
59m
Merged PRs (30d)
3

Description

Subject of the issue

When delegating using **kwargs, the spec fails when passed no keyword arguments in 2.7 (no issues with 3.0).

Your environment
  • Ruby version: 2.7
  • rspec-mocks version: 3.11.1
Steps to reproduce
# frozen_string_literal: true

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.11.0"
  gem "rspec-mocks", "3.11.1"
end

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

def call(client, name, *args, **kwargs)
  client.public_send(name, *args, **kwargs)
end

RSpec.describe 'args broken' do
  let(:client) { double('@client') }

  it 'works' do
    expect(client).to receive(:foo).with('a', 1)

    call(client, :foo, 'a', 1)
  end

  it 'works with keyword args' do
    expect(client).to receive(:foo).with('a', 1, baz: 5)

    call(client, :foo, 'a', 1, baz: 5)
  end
end
Expected behavior
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using bundler 2.3.4
Using rspec-support 3.11.0
Using diff-lcs 1.5.0
Using rspec-core 3.11.0
Using rspec-expectations 3.11.0
Using rspec-mocks 3.11.0
Using rspec 3.11.0
Ruby version is: 2.7.5
..

Finished in 0.00934 seconds (files took 0.06848 seconds to load)
2 examples, 0 failures
Actual behavior
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using bundler 2.3.4
Using diff-lcs 1.5.0
Using rspec-support 3.11.0
Using rspec-expectations 3.11.0
Using rspec-core 3.11.0
Using rspec-mocks 3.11.1
Using rspec 3.11.0
Ruby version is: 2.7.5
F.

Failures:

  1) args broken works
     Failure/Error: client.public_send(name, *args, **kwargs)
       #<Double "@client"> received unexpected message :foo with ("a", 1)
     # new.rb:21:in `public_send'
     # new.rb:21:in `call'
     # new.rb:30:in `block (2 levels) in <main>'

Finished in 0.00692 seconds (files took 0.07046 seconds to load)
2 examples, 1 failure

Failed examples:

rspec new.rb:27 # args broken works

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure from the issue's inline example on Ruby 2.7 with rspec-mocks 3.11.1, comparing it with 3.11.0. Start at the delegated client.public_send call and the rspec-mocks argument matching path; done means both examples pass with no unexpected-message failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.