Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Countable to a reusable module #1252

Open
pirj opened this issue Dec 23, 2020 · 3 comments
Open

Extract Countable to a reusable module #1252

pirj opened this issue Dec 23, 2020 · 3 comments

Comments

@pirj
Copy link
Member

pirj commented Dec 23, 2020

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).

@JonRowe
Copy link
Member

JonRowe commented Dec 23, 2020

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

@pirj
Copy link
Member Author

pirj commented Dec 28, 2020

have_enqueued_mail is yet another example.

@JonRowe
Copy link
Member

JonRowe commented Dec 28, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants