Skip to content

Commit

Permalink
Change to ensure option can be marked as required or optional
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Apr 6, 2020
1 parent 8ba9d77 commit 87b3c43
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spec/unit/parse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,33 @@ def new_command(&block)
expect(cmd.params[:foo]).to eq(["baz", "qux"])
end

it "requires an option to be present" do
cmd = new_command do
option :foo do
required
long "--foo string"
end
end

expect {
cmd.parse([])
}.to raise_error(TTY::Option::MissingParameter,
"need to provide --foo option")
end

it "marks an option as optional with required argument" do
cmd = new_command do
option :foo do
optional
long "--foo string"
end
end

cmd.parse([])

expect(cmd.params[:foo]).to eq(nil)
end

it "requires an option to have an argument" do
cmd = new_command do
option :foo, long: "--foo string"
Expand Down

0 comments on commit 87b3c43

Please sign in to comment.