rspec / rspec/rspec-activemodel-mocks

(Feature request) Make mocked model to_s more elegant

Open
#30 0 comments 1 reaction 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

Current behaviour:

m = mock_model(Transaction)
m.to_s # Returns something like Transaction_#<RSpec::ExampleGroups::0x00564be9720728>

I would like to_s to also show what is stubbed inside that model, so that the spec is easier to read. For example:

m = mock_model(Transaction, type: :transfer)
m.to_s # Transaction(type: :transfer) #<RSpec::ExampleGroups::0x00564be9720728>

it { is_expected.to be_able_to(:read, mock_model(Transaction, type: :transfer)) }
# Output: It should be able to read Transaction(type: :transfer) #<RSpec::ExampleGroups::0x00564be9720728>

It will look similar to what ActiveRecord does. What do you think?

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 by locating the mock_model implementation in rspec-activemodel-mocks and inspect how its to_s output is generated. Use the Transaction examples in the issue to define the expected representation, then add coverage showing stubbed attributes in the output and confirm existing output remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
testing
Issue type
Feature
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.