Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Rails 7.1 breaks receive().with #1530

@palkan

Description

@palkan

Your environment

  • Ruby version: 3.2
  • rspec-mocks version: 3.12.2
  • Rails version: main.

Steps to reproduce

In a Rails application (i.e., with Rails loaded), define a method expectation:

mock = instance_double("Hash")
allow(mock).to receive(:key?).with(:x) { 1 }

expect(mock.key?(:x)).to eq 1

Expected behavior

Pass.

Actual behavior

ArgumentError:
       wrong number of arguments (given 1, expected 0)
     # ../rails/activesupport/lib/active_support/core_ext/object/with.rb:24:in `with'

What happened?

Rails monkey-patched Object#with rails/rails#46681 /cc @byroot

RSpec receive matcher defines chain methods only for undefined methods:

MessageExpectation.public_instance_methods(false).each do |method|
next if method_defined?(method)

Since #with is defined on Object, the with modifier is no longer available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions