rspec-expectations icon indicating copy to clipboard operation
rspec-expectations copied to clipboard

Extract Countable to a reusable module

Open pirj opened this issue 4 years ago • 3 comments

I've seen a lot of custom matchers, and ours included, reimplement the same interface of #once, #twice, #at_least etc. Sometimes partially, sometimes completely.

A Countable module can be used in matchers from Expectations (include) and Mocks (receive), and third-party extensions.

Expected behavior

RSpec::Matchers.define :drink_tea do |expected|
  include RSpec::Matchers::Countable
end

it { is_expected.to drink_tea.twice }

The problem here is that Mocks do not depend on Expectations, and Support might not be the best place for it (can't find the discussion about extracting, can only recall the word "bag" was used).

pirj avatar Dec 23 '20 20:12 pirj

I'm not sure we want to make it a public api though...

JonRowe avatar Dec 23 '20 22:12 JonRowe

have_enqueued_mail is yet another example.

pirj avatar Dec 28 '20 13:12 pirj

Mocks cannot depend on Expectations for such core functionality, if you do want to extract it, then it would need to go to support. The current implementation is not suitable for extraction as we would need a single concrete way for a 3rd party to define how countable works.

JonRowe avatar Dec 28 '20 13:12 JonRowe

Closing due to inactivity during the monorepo migration, but feel free to reopen there if someone works on it.

JonRowe avatar Nov 27 '24 22:11 JonRowe