-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add super
advice for hooks
#35
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -480,6 +480,45 @@ _ { raise_exception }.must_raise TypeError | |
|
||
Check the http://docs.seattlerb.org/minitest/Minitest/Expectations.html[Minitest::Expectations doc] for more information about its usage. | ||
|
||
=== Hooks [[hooks]] | ||
|
||
If using a module containing `setup` or `teardown` methods, be sure to call `super` in the test class `setup` or | ||
`teardown`. | ||
|
||
[source,ruby] | ||
---- | ||
|
||
# bad | ||
|
||
class TestMeme < Minitest::Test | ||
include MyHelper | ||
|
||
def setup | ||
do_something | ||
end | ||
|
||
def teardown | ||
clean_something | ||
end | ||
end | ||
|
||
# good | ||
|
||
class TestMeme < Minitest::Test | ||
include MyHelper | ||
|
||
def setup | ||
super | ||
do_something | ||
end | ||
|
||
def teardown | ||
clean_something | ||
super | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, as the example code, it may be better to set up the superclass first. def setup
super
do_something
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. I've also added a |
||
end | ||
end | ||
---- | ||
|
||
== Related Guides | ||
|
||
* https://rubystyle.guide[Ruby Style Guide] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be even clearer :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered that, but the Minitest docs seem to indicate that 'lifecycle hooks' are things such as
before_setup
andafter_teardown
, which are "meant for library writers, NOT for regular test authors."https://www.rubydoc.info/gems/minitest/5.9.1/Minitest/Test/LifecycleHooks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get it. Thank you for the explanation!