rspec / rspec/rspec-activemodel-mocks

#initialize instance private method issue

Open
#23 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
119
Forks
31
Avg merge
5h 47m
Merged PRs (30d)
2

Description

mock_model("Book")

allow(Book).to receive(:new).with({}) { book_instance }

Wrong number of arguments. Expected 0, got 1.
The reason is Book.instance_method(:initialize).arity is 0;
Which is supposed to be -1. Book.new takes *args, so initialize is failing when testing with RSpec.

Contributor guide

No contributing guide indexed for this repository

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

Start at the mock_model("Book") entry point and trace how Book.new and Book.instance_method(:initialize).arity are handled when the model accepts *args. Reproduce the reported RSpec case with allow(Book) to receive(:new).with({}), then add or update coverage so the arity is treated as expected and the wrong-argument failure no longer occurs.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.