summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-06-26 13:04:17 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2018-06-26 13:04:17 -0700
commit5ee0a74e40c15c17933c936a860acc4469ca82e3 (patch)
treef13476f1185a5f188649d30a152d4a81e40ad81c /spec
parentfd0ba0dabe1c113919b34343fd6777916905c42c (diff)
downloadmixlib-cli-5ee0a74e40c15c17933c936a860acc4469ca82e3.tar.gz
remove hashrockets syntax
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/cli_spec.rb104
-rw-r--r--spec/spec_helper.rb2
2 files changed, 53 insertions, 53 deletions
diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb
index 20d3285..ed890b5 100644
--- a/spec/mixlib/cli_spec.rb
+++ b/spec/mixlib/cli_spec.rb
@@ -27,21 +27,21 @@ describe Mixlib::CLI do
describe "class method" do
describe "option" do
it "allows you to set a config option with a hash" do
- expect(TestCLI.option(:config_file, :short => "-c CONFIG")).to eql({ :short => "-c CONFIG" })
+ expect(TestCLI.option(:config_file, short: "-c CONFIG")).to eql({ short: "-c CONFIG" })
end
end
describe "options" do
it "returns the current options hash" do
- TestCLI.option(:config_file, :short => "-c CONFIG")
- expect(TestCLI.options).to eql({ :config_file => { :short => "-c CONFIG" } })
+ TestCLI.option(:config_file, short: "-c CONFIG")
+ expect(TestCLI.options).to eql({ config_file: { short: "-c CONFIG" } })
end
end
describe "options=" do
it "allows you to set the full options with a single hash" do
- TestCLI.options = { :config_file => { :short => "-c CONFIG" } }
- expect(TestCLI.options).to eql({ :config_file => { :short => "-c CONFIG" } })
+ TestCLI.options = { config_file: { short: "-c CONFIG" } }
+ expect(TestCLI.options).to eql({ config_file: { short: "-c CONFIG" } })
end
end
@@ -69,24 +69,24 @@ describe Mixlib::CLI do
end
it "sets the options to the class defined options, plus defaults" do
- TestCLI.option(:config_file, :short => "-l LOG")
+ TestCLI.option(:config_file, short: "-l LOG")
cli = TestCLI.new
expect(cli.options).to eql({
- :config_file => {
- :short => "-l LOG",
- :on => :on,
- :boolean => false,
- :required => false,
- :proc => nil,
- :show_options => false,
- :exit => nil,
- :in => nil,
+ config_file: {
+ short: "-l LOG",
+ on: :on,
+ boolean: false,
+ required: false,
+ proc: nil,
+ show_options: false,
+ exit: nil,
+ in: nil,
},
})
end
it "sets the default config value for any options that include it" do
- TestCLI.option(:config_file, :short => "-l LOG", :default => :debug)
+ TestCLI.option(:config_file, short: "-l LOG", default: :debug)
@cli = TestCLI.new
expect(@cli.config[:config_file]).to eql(:debug)
end
@@ -99,29 +99,29 @@ describe Mixlib::CLI do
end
it "presents the arguments in the banner" do
- TestCLI.option(:config_file, :short => "-l LOG")
+ TestCLI.option(:config_file, short: "-l LOG")
@cli = TestCLI.new
expect(@cli.opt_parser.to_s).to match(/-l LOG/)
end
it "honors :on => :tail options in the banner" do
- TestCLI.option(:config_file, :short => "-l LOG")
- TestCLI.option(:help, :short => "-h", :boolean => true, :on => :tail)
+ TestCLI.option(:config_file, short: "-l LOG")
+ TestCLI.option(:help, short: "-h", boolean: true, on: :tail)
@cli = TestCLI.new
expect(@cli.opt_parser.to_s.split("\n").last).to match(/-h/)
end
it "honors :on => :head options in the banner" do
- TestCLI.option(:config_file, :short => "-l LOG")
- TestCLI.option(:help, :short => "-h", :boolean => true, :on => :head)
+ TestCLI.option(:config_file, short: "-l LOG")
+ TestCLI.option(:help, short: "-h", boolean: true, on: :head)
@cli = TestCLI.new
expect(@cli.opt_parser.to_s.split("\n")[1]).to match(/-h/)
end
it "presents the arguments in alphabetical order in the banner" do
- TestCLI.option(:alpha, :short => "-a ALPHA")
- TestCLI.option(:beta, :short => "-b BETA")
- TestCLI.option(:zeta, :short => "-z ZETA")
+ TestCLI.option(:alpha, short: "-a ALPHA")
+ TestCLI.option(:beta, short: "-b BETA")
+ TestCLI.option(:zeta, short: "-z ZETA")
@cli = TestCLI.new
output_lines = @cli.opt_parser.to_s.split("\n")
expect(output_lines[1]).to match(/-a ALPHA/)
@@ -133,7 +133,7 @@ describe Mixlib::CLI do
describe "parse_options" do
it "sets the corresponding config value for non-boolean arguments" do
- TestCLI.option(:config_file, :short => "-c CONFIG")
+ TestCLI.option(:config_file, short: "-c CONFIG")
@cli = TestCLI.new
@cli.parse_options([ "-c", "foo.rb" ])
expect(@cli.config[:config_file]).to eql("foo.rb")
@@ -141,8 +141,8 @@ describe Mixlib::CLI do
it "sets the corresponding config value according to a supplied proc" do
TestCLI.option(:number,
- :short => "-n NUMBER",
- :proc => Proc.new { |config| config.to_i + 2 }
+ short: "-n NUMBER",
+ proc: Proc.new { |config| config.to_i + 2 }
)
@cli = TestCLI.new
@cli.parse_options([ "-n", "2" ])
@@ -151,8 +151,8 @@ describe Mixlib::CLI do
it "passes the existing value to two-argument procs" do
TestCLI.option(:number,
- :short => "-n NUMBER",
- :proc => Proc.new { |value, existing| existing ||= []; existing << value; existing }
+ short: "-n NUMBER",
+ proc: Proc.new { |value, existing| existing ||= []; existing << value; existing }
)
@cli = TestCLI.new
@cli.parse_options([ "-n", "2", "-n", "3" ])
@@ -160,45 +160,45 @@ describe Mixlib::CLI do
end
it "sets the corresponding config value to true for boolean arguments" do
- TestCLI.option(:i_am_boolean, :short => "-i", :boolean => true)
+ TestCLI.option(:i_am_boolean, short: "-i", boolean: true)
@cli = TestCLI.new
@cli.parse_options([ "-i" ])
expect(@cli.config[:i_am_boolean]).to be true
end
it "sets the corresponding config value to false when a boolean is prefixed with --no" do
- TestCLI.option(:i_am_boolean, :long => "--[no-]bool", :boolean => true)
+ TestCLI.option(:i_am_boolean, long: "--[no-]bool", boolean: true)
@cli = TestCLI.new
@cli.parse_options([ "--no-bool" ])
expect(@cli.config[:i_am_boolean]).to be false
end
it "exits if a config option has :exit set" do
- TestCLI.option(:i_am_exit, :short => "-x", :boolean => true, :exit => 0)
+ TestCLI.option(:i_am_exit, short: "-x", boolean: true, exit: 0)
@cli = TestCLI.new
expect(lambda { @cli.parse_options(["-x"]) }).to raise_error(SystemExit)
end
it "exits if a required option is missing" do
- TestCLI.option(:require_me, :short => "-r", :boolean => true, :required => true)
+ TestCLI.option(:require_me, short: "-r", boolean: true, required: true)
@cli = TestCLI.new
expect(lambda { @cli.parse_options([]) }).to raise_error(SystemExit)
end
it "exits if option is not included in the list and required" do
- TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :required => true)
+ TestCLI.option(:inclusion, short: "-i val", in: %w{one two}, required: true)
@cli = TestCLI.new
expect(lambda { @cli.parse_options(["-i", "three"]) }).to raise_error(SystemExit)
end
it "exits if option is not included in the list and not required" do
- TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :required => false)
+ TestCLI.option(:inclusion, short: "-i val", in: %w{one two}, required: false)
@cli = TestCLI.new
expect(lambda { @cli.parse_options(["-i", "three"]) }).to raise_error(SystemExit)
end
it "doesn't exit if option is nil and not required" do
- TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :required => false)
+ TestCLI.option(:inclusion, short: "-i val", in: %w{one two}, required: false)
@cli = TestCLI.new
expect do
expect(@cli.parse_options([])).to eql []
@@ -206,54 +206,54 @@ describe Mixlib::CLI do
end
it "exit if option is nil and required" do
- TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :required => true)
+ TestCLI.option(:inclusion, short: "-i val", in: %w{one two}, required: true)
@cli = TestCLI.new
expect(lambda { @cli.parse_options([]) }).to raise_error(SystemExit)
end
it "raises ArgumentError if options key :in is not an array" do
- TestCLI.option(:inclusion, :short => "-i val", :in => "foo", :required => true)
+ TestCLI.option(:inclusion, short: "-i val", in: "foo", required: true)
@cli = TestCLI.new
expect(lambda { @cli.parse_options(["-i", "three"]) }).to raise_error(ArgumentError)
end
it "doesn't exit if option is included in the list" do
- TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :required => true)
+ TestCLI.option(:inclusion, short: "-i val", in: %w{one two}, required: true)
@cli = TestCLI.new
@cli.parse_options(["-i", "one"])
expect(@cli.config[:inclusion]).to eql("one")
end
it "changes description if :in key is specified" do
- TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :description => "desc", :required => false)
+ TestCLI.option(:inclusion, short: "-i val", in: %w{one two}, description: "desc", required: false)
@cli = TestCLI.new
@cli.parse_options(["-i", "one"])
expect(@cli.options[:inclusion][:description]).to eql("desc (included in ['one', 'two'])")
end
it "doesn't exit if a required option is specified" do
- TestCLI.option(:require_me, :short => "-r", :boolean => true, :required => true)
+ TestCLI.option(:require_me, short: "-r", boolean: true, required: true)
@cli = TestCLI.new
@cli.parse_options(["-r"])
expect(@cli.config[:require_me]).to be true
end
it "doesn't exit if a required boolean option is specified and false" do
- TestCLI.option(:require_me, :long => "--[no-]req", :boolean => true, :required => true)
+ TestCLI.option(:require_me, long: "--[no-]req", boolean: true, required: true)
@cli = TestCLI.new
@cli.parse_options(["--no-req"])
expect(@cli.config[:require_me]).to be false
end
it "doesn't exit if a required option is specified and empty" do
- TestCLI.option(:require_me, :short => "-r VALUE", :required => true)
+ TestCLI.option(:require_me, short: "-r VALUE", required: true)
@cli = TestCLI.new
@cli.parse_options(["-r", ""])
expect(@cli.config[:require_me]).to eql("")
end
it "preserves all of the commandline arguments, ARGV" do
- TestCLI.option(:config_file, :short => "-c CONFIG")
+ TestCLI.option(:config_file, short: "-c CONFIG")
@cli = TestCLI.new
argv_old = ARGV.dup
ARGV.replace ["-c", "foo.rb"]
@@ -263,7 +263,7 @@ describe Mixlib::CLI do
end
it "preserves and return any un-parsed elements" do
- TestCLI.option(:party, :short => "-p LOCATION")
+ TestCLI.option(:party, short: "-p LOCATION")
@cli = TestCLI.new
expect(@cli.parse_options([ "easy", "-p", "opscode", "hard" ])).to eql(%w{easy hard})
expect(@cli.cli_arguments).to eql(%w{easy hard})
@@ -274,7 +274,7 @@ describe Mixlib::CLI do
context "when configured to separate default options" do
before do
TestCLI.use_separate_default_options true
- TestCLI.option(:defaulter, :short => "-D SOMETHING", :default => "this is the default")
+ TestCLI.option(:defaulter, short: "-D SOMETHING", default: "this is the default")
@cli = TestCLI.new
end
@@ -294,12 +294,12 @@ describe Mixlib::CLI do
context "when subclassed" do
before do
- TestCLI.options = { :arg1 => { :boolean => true } }
+ TestCLI.options = { arg1: { boolean: true } }
end
it "retains previously defined options from parent" do
class T1 < TestCLI
- option :arg2, :boolean => true
+ option :arg2, boolean: true
end
expect(T1.options[:arg1]).to be_a(Hash)
expect(T1.options[:arg2]).to be_a(Hash)
@@ -308,7 +308,7 @@ describe Mixlib::CLI do
it "isn't able to modify parent classes options" do
class T2 < TestCLI
- option :arg2, :boolean => true
+ option :arg2, boolean: true
end
T2.options[:arg1][:boolean] = false
expect(T2.options[:arg1][:boolean]).to be false
@@ -317,10 +317,10 @@ describe Mixlib::CLI do
it "passes its options onto child" do
class T3 < TestCLI
- option :arg2, :boolean => true
+ option :arg2, boolean: true
end
class T4 < T3
- option :arg3, :boolean => true
+ option :arg3, boolean: true
end
3.times do |i|
expect(T4.options["arg#{i + 1}".to_sym]).to be_a(Hash)
@@ -329,7 +329,7 @@ describe Mixlib::CLI do
it "also works with an option that's an array" do
class T5 < TestCLI
- option :arg2, :default => []
+ option :arg2, default: []
end
class T6 < T5
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index e2956c4..13432c6 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -8,7 +8,7 @@ class TestCLI
end
RSpec.configure do |config|
- config.filter_run :focus => true
+ config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.warnings = true
end