spec/clamp/option/definition_spec.rb in clamp-1.2.1 vs spec/clamp/option/definition_spec.rb in clamp-1.3.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require "spec_helper" describe Clamp::Option::Definition do context "with String argument" do @@ -25,11 +27,11 @@ it "is derived from the (long) switch" do expect(option.attribute_name).to eql "key_file" end it "can be overridden" do - option = described_class.new("--key-file", "FILE", "SSH identity", :attribute_name => "ssh_identity") + option = described_class.new("--key-file", "FILE", "SSH identity", attribute_name: "ssh_identity") expect(option.attribute_name).to eql "ssh_identity" end end @@ -47,11 +49,11 @@ option = described_class.new("-n", "N", "iterations") expect(option.default_value).to eql nil end it "can be overridden" do - option = described_class.new("-n", "N", "iterations", :default => 1) + option = described_class.new("-n", "N", "iterations", default: 1) expect(option.default_value).to eql 1 end end @@ -147,11 +149,11 @@ end context "with an associated environment variable" do let(:option) do - described_class.new("-x", "X", "mystery option", :environment_variable => "APP_X") + described_class.new("-x", "X", "mystery option", environment_variable: "APP_X") end describe "#help" do it "describes environment variable" do @@ -161,11 +163,11 @@ end context "and a default value" do let(:option) do - described_class.new("-x", "X", "mystery option", :environment_variable => "APP_X", :default => "xyz") + described_class.new("-x", "X", "mystery option", environment_variable: "APP_X", default: "xyz") end describe "#help" do it "describes both environment variable and default" do @@ -179,11 +181,11 @@ end context "multivalued" do let(:option) do - described_class.new(["-H", "--header"], "HEADER", "extra header", :multivalued => true) + described_class.new(["-H", "--header"], "HEADER", "extra header", multivalued: true) end it "is multivalued" do expect(option).to be_multivalued end @@ -193,11 +195,11 @@ it "defaults to an empty Array" do expect(option.default_value).to eql [] end it "can be overridden" do - option = described_class.new("-H", "HEADER", "extra header", :multivalued => true, :default => [1, 2, 3]) + option = described_class.new("-H", "HEADER", "extra header", multivalued: true, default: [1, 2, 3]) expect(option.default_value).to eql [1, 2, 3] end end @@ -245,40 +247,40 @@ describe "a required option" do it "rejects :default" do expect do described_class.new("--key-file", "FILE", "SSH identity", - :required => true, :default => "hello") + required: true, default: "hello") end.to raise_error(ArgumentError) end it "rejects :flag options" do expect do - described_class.new("--awesome", :flag, "Be awesome?", :required => true) + described_class.new("--awesome", :flag, "Be awesome?", required: true) end.to raise_error(ArgumentError) end end describe "a hidden option" do - let(:option) { described_class.new("--unseen", :flag, "Something", :hidden => true) } + let(:option) { described_class.new("--unseen", :flag, "Something", hidden: true) } it "is hidden" do expect(option).to be_hidden end end describe "a hidden option in a command" do let(:command_class) do Class.new(Clamp::Command) do - option "--unseen", :flag, "Something", :hidden => true + option "--unseen", :flag, "Something", hidden: true def execute # this space intentionally left blank end end end it "is not shown in the help" do - expect(command_class.help("foo")).not_to match /^ +--unseen +Something$/ + expect(command_class.help("foo")).not_to match(/^ +--unseen +Something$/) end it "sets the expected accessor" do command = command_class.new("foo") command.run(["--unseen"])