summaryrefslogtreecommitdiff
path: root/test/optparse
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-18 15:15:59 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-18 15:18:36 +0900
commit46fa301e82d50161fc7ec8e455d9d498b15b2c7a (patch)
treea05e57d865b3c255a4b9022644e8445e2516530e /test/optparse
parente50b8949fad96a30226e4122172822a2a4c7301d (diff)
Use DidYouMean.formatter
Instead of building messages separately.
Diffstat (limited to 'test/optparse')
-rw-r--r--test/optparse/test_did_you_mean.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/test/optparse/test_did_you_mean.rb b/test/optparse/test_did_you_mean.rb
index 4d8e272..c5beaa4 100644
--- a/test/optparse/test_did_you_mean.rb
+++ b/test/optparse/test_did_you_mean.rb
@@ -8,15 +8,26 @@ class TestOptionParser::DidYouMean < TestOptionParser
@opt.def_option("--foo", Integer) { |v| @foo = v }
@opt.def_option("--bar", Integer) { |v| @bar = v }
@opt.def_option("--baz", Integer) { |v| @baz = v }
+ @formatter = ::DidYouMean.formatter
end
- def test_did_you_mean
- assert_raise(OptionParser::InvalidOption) do
- begin
- @opt.permute!(%w"--baa")
- ensure
- assert_equal("invalid option: --baa\nDid you mean? baz\n bar", $!.message)
- end
+ def teardown
+ ::DidYouMean.formatter = @formatter
+ end
+
+
+ def test_plain
+ ::DidYouMean.formatter = ::DidYouMean::PlainFormatter.new
+ assert_raise_with_message(OptionParser::InvalidOption, /invalid option: --baa\nDid you mean\?\s+baz\s+bar\Z/) do
+ @opt.permute!(%w"--baa")
+ end
+ end
+
+ def test_verbose
+ require 'did_you_mean/formatters/verbose_formatter'
+ ::DidYouMean.formatter = ::DidYouMean::VerboseFormatter.new
+ assert_raise_with_message(OptionParser::InvalidOption, /invalid option: --baa\n\s+Did you mean\?\s+baz\s+bar\s*\Z/) do
+ @opt.permute!(%w"--baa")
end
end
end