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

Add super advice for hooks #35

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Copy link
Member

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

Suggested change
=== Hooks [[hooks]]
=== Lifecycle Hooks [[lifecycle-hooks]]

Copy link
Contributor Author

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 and after_teardown, which are "meant for library writers, NOT for regular test authors."

https://www.rubydoc.info/gems/minitest/5.9.1/Minitest/Test/LifecycleHooks

Copy link
Member

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!


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
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. I've also added a teardown example as I believe that would typically be in the opposite order.

end
end
----

== Related Guides

* https://rubystyle.guide[Ruby Style Guide]
Expand Down