From 840b5a627d708cef7065602a581547ac07acd64e Mon Sep 17 00:00:00 2001 From: "Marc A. Paradise" Date: Thu, 6 Jun 2019 15:24:49 -0400 Subject: Code review updates for deprecated_option Signed-off-by: Marc A. Paradise --- spec/mixlib/cli/formatter_spec.rb | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spec/mixlib/cli/formatter_spec.rb (limited to 'spec') diff --git a/spec/mixlib/cli/formatter_spec.rb b/spec/mixlib/cli/formatter_spec.rb new file mode 100644 index 0000000..5500528 --- /dev/null +++ b/spec/mixlib/cli/formatter_spec.rb @@ -0,0 +1,43 @@ + +require "mixlib/cli/formatter" + +describe Mixlib::CLI::Formatter do + Formatter = Mixlib::CLI::Formatter + context "combined_option_display_name" do + it "converts --option with short -o to '-s/--option'" do + expect(Formatter.combined_option_display_name("-o", "--option")).to eql "-o/--option" + end + + it "converts --option with no short to '--option'" do + expect(Formatter.combined_option_display_name(nil, "--option")).to eql "--option" + end + it "converts short -o with no long option to '-o'" do + expect(Formatter.combined_option_display_name("-o", nil)).to eql"-o" + end + + it "converts options the same way even with an argument present" do + expect(Formatter.combined_option_display_name("-o arg1", "--option arg1")).to eql "-o/--option" + end + + it "converts options to a blank string if neither short nor long are present" do + expect(Formatter.combined_option_display_name(nil, nil)).to eql "" + end + end + + context "friendly_opt_list" do + it "for a single item it quotes it and returns it as a string" do + expect(Formatter.friendly_opt_list(%w{hello})).to eql "'hello'" + end + it "for two items returns ..." do + expect(Formatter.friendly_opt_list(%w{hello world})).to eql "'hello' or 'world'" + end + it "for three items returns..." do + expect(Formatter.friendly_opt_list(%w{hello green world})).to eql "'hello', 'green', or 'world'" + end + it "for more than three items creates a list in the same was as three items" do + expect(Formatter.friendly_opt_list(%w{hello green world good morning})).to eql "'hello', 'green', 'world', 'good', or 'morning'" + end + + end + +end -- cgit v1.2.1