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

Ineffective assertion tests #157

Closed
nanobowers opened this issue May 18, 2024 · 0 comments · Fixed by #160
Closed

Ineffective assertion tests #157

nanobowers opened this issue May 18, 2024 · 0 comments · Fixed by #160
Assignees
Labels

Comments

@nanobowers
Copy link
Collaborator

Some assertion tests do not do what they advertise:

$ rg 'assert_raises\([A-Za-z]+,' 
optimist/parser_test.rb
870:    assert_raises(CommandlineError, /--one.*--two/) { @p.parse %w(--one --two) }
907:    assert_raises(CommandlineError, /--one.*--two/) { @p.parse %w(--one) }
908:    assert_raises(CommandlineError, /--one.*--two/) { @p.parse %w(--two) }
916:    assert_raises(CommandlineError, /arg2/) { @p.parse(%w(--arg1)) }
917:    assert_raises(CommandlineError, /arg1/) { @p.parse(%w(--arg2)) }
1227:    assert_raises(CommandlineError, /unknown argument '--lib'/) do
1246:    assert_raises(CommandlineError, /specified multiple times/) do
1351:    assert_raises(RuntimeError, "good") do
1360:    assert_raises(RuntimeError, "good") do

The documentation for assert_raises says it takes one or more exceptions. Oops.
https://rubydoc.info/gems/minitest/Minitest%2FAssertions:assert_raises

thus, the Regexp or String given as the second argument is not doing anything.
These should be changed to use the assert_raises_errmatch helper function which takes a single exception type and a Regexp.

Per discussion with @Fryguy on a different PR there it would be good to improve some of the tests' message checking since that is rarely happening.

@miq-bot add-label test

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

Successfully merging a pull request may close this issue.

2 participants