blob: 2f7730b633163759904053ec83f01bf62e076983 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
require 'test_helper'
# All raised errors tested here
describe Slop::MissingArgument do
it "raises when an argument is missing" do
opts = Slop::Options.new
opts.string "-n", "--name"
assert_raises(Slop::MissingArgument) { opts.parse %w(--name) }
#Assert returns the argument question
begin
opts.parse %w(--name)
rescue Slop::MissingArgument => e
assert_equal(e.flags, ["-n", "--name"])
end
end
it "does not raise when errors are suppressed" do
opts = Slop::Options.new(suppress_errors: true)
opts.string "-n", "--name"
opts.parse %w(--name)
end
it "does not raise if '--' appears as the first argument" do
opts = Slop::Options.new
opts.string "-n", "--name"
opts.parse %w(-- --name)
end
end
describe Slop::UnknownOption do
it "raises when an option is unknown" do
opts = Slop::Options.new
opts.string "-n", "--name"
assert_raises(Slop::UnknownOption) { opts.parse %w(--foo) }
#Assert returns the unknown option in question
begin
opts.parse %w(--foo)
rescue Slop::UnknownOption => e
assert_equal(e.flag, "--foo")
end
end
it "does not raise when errors are suppressed" do
opts = Slop::Options.new(suppress_errors: true)
opts.string "-n", "--name"
opts.parse %w(--foo)
end
end
|