Skip to content

Commit

Permalink
Check converion error propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Apr 3, 2020
1 parent c530519 commit 7fd52a4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/unit/param_conversion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
expect(described_class[param, "12"]).to eq(12)
end

it "fails to convert parameter value to expected type" do
param = TTY::Option::Parameter::Argument.create(:foo, convert: :int)

expect {
described_class[param, "bar"]
}.to raise_error(TTY::Option::InvalidConversionArgument,
"Invalid value of \"bar\" for :int conversion")
end

it "converts parameter value to expected type with a block" do
param = TTY::Option::Parameter::Argument.create(:foo,
convert: ->(val) { val.to_i })
Expand Down

0 comments on commit 7fd52a4

Please sign in to comment.