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

Minitest: is there a recommended way to use shoulda-matchers without using shoulda-context ? #1571

Open
lioneldebauge opened this issue Sep 22, 2023 · 2 comments

Comments

@lioneldebauge
Copy link

lioneldebauge commented Sep 22, 2023

Hello 👋

My team is looking into adding shoulda-matchers to our Minitest test suite. Is it possible to use shoulda-matchers without shoulda-context gem ? If so what is the recommended way ?

Documentation suggests it in "Getting Started" section below but all examples assume the usage of should method.

https://matchers.shoulda.io/docs/v5.3.0/#minitest

Thanks for any help that you would be willing to give us and for this very useful gem 🙏

@mcmire
Copy link
Collaborator

mcmire commented Oct 29, 2023

Hi @lioneldebauge, sorry for the delay. It is possible to use this without shoulda-context, yes. I haven't tried it, but others have found success using the minitest-matchers_vaccine gem. See: #825 (comment).

Hope that helps!

@lioneldebauge
Copy link
Author

@mcmire you just made my day. Thanks a lot for your answer ! Should we modify the documentation to include a reference ? I can open a PR if needed.


For reference for others who might need it. I'm using Minitest::Spec::DSL

# in a helper file

def assert_must(matcher, subject, msg = nil)
  assert matcher.matches?(subject), msg
end

# in a model file

describe("validations")
  let(:user) { User.new }

  it { assert_must validates_presence_of :name, user }
end

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