Skip to content

Commit

Permalink
Add specs to ensure parser required check correct behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Apr 19, 2020
1 parent 22f51b2 commit d8c760f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/unit/parser/required_check_spec.rb
@@ -0,0 +1,31 @@
# frozen_string_literal: true

RSpec.describe TTY::Option::Parser::RequiredCheck do
it "passes required check" do
param = TTY::Option::Parameter::Option.create(:foo, required: true)
errors = []
aggregator = ->(err) { errors << err }
required_check = described_class.new(aggregator)
required_check << param

required_check.delete(param)

required_check.()

expect(errors).to eq([])
end

it "fails required check" do
param = TTY::Option::Parameter::Option.create(:foo)
errors = []
aggregator = ->(err) { errors << err }
required_check = described_class.new(aggregator)
required_check << param

required_check.()

error = TTY::Option::MissingParameter.new("need to provide '--foo' option")

expect(errors).to eq([error])
end
end

0 comments on commit d8c760f

Please sign in to comment.