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

How do I define asserting helpers? #998

Closed
Nakilon opened this issue May 5, 2024 · 3 comments
Closed

How do I define asserting helpers? #998

Nakilon opened this issue May 5, 2024 · 3 comments

Comments

@Nakilon
Copy link

Nakilon commented May 5, 2024

I use minitest with spec syntax.
I have a complex stubbing method that invokes such methods as assert_equal, assert_operator, etc. I want to reuse it in another tests file so I need to put it in some common place to require, but usual def elsewhere will not find those assertion methods. What is the way/place to define the asserting helpers at? Maybe some Minitest class that I have to extend?

@zenspider
Copy link
Collaborator

Such a pain, no? Always bites me. 2 easy (cheat?) ways I know of... go ahead and shove it in Minitest::Test (or Spec) or include Minitest::Assertions in your module.

If it is app/lib specific, then I usually put em in a Test/Spec subclass of their own that I subclass from. For specs you can "register" this new spec type:

  Minitest::Spec.register_spec_type(/XTest$/, MyCustomTest)
# or
  Minitest::Spec.register_spec_type(MyCustomTest) do |desc|
    desc.superclass.is_a? Something # or whatever
  end

@zenspider
Copy link
Collaborator

Please close if your questions have been adequately addressed.

@Nakilon
Copy link
Author

Nakilon commented May 17, 2024

Sure. I'll test the approaches when I find time and report.

@Nakilon Nakilon closed this as completed May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants