blob: be5b09124bee74f4f7fa477d608c735d641cc21c (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
require 'helper'
describe Pry::Hooks do
before do
Pry::CLI.reset
end
describe "parsing options" do
it 'should raise if no options defined' do
lambda { Pry::CLI.parse_options(["--nothing"]) }.should.raise Pry::CLI::NoOptionsError
end
it "should remove args from ARGV by default" do
ARGV << '-v'
Pry::CLI.add_options do
on :v, "Display the Pry version" do
# irrelevant
end
end.parse_options
ARGV.include?('-v').should == false
end
end
describe "adding options" do
it "should be able to add an option" do
run = false
Pry::CLI.add_options do
on :optiontest, "A test option" do
run = true
end
end.parse_options(["--optiontest"])
run.should == true
end
it "should be able to add multiple options" do
run = false
run2 = false
Pry::CLI.add_options do
on :optiontest, "A test option" do
run = true
end
end.add_options do
on :optiontest2, "Another test option" do
run2 = true
end
end.parse_options(["--optiontest", "--optiontest2"])
run.should.be.true
run2.should.be.true
end
end
describe "processing options" do
it "should be able to process an option" do
run = false
Pry::CLI.add_options do
on :optiontest, "A test option"
end.add_option_processor do |opts|
run = true if opts.present?(:optiontest)
end.parse_options(["--optiontest"])
run.should == true
end
it "should be able to process multiple options" do
run = false
run2 = false
Pry::CLI.add_options do
on :optiontest, "A test option"
on :optiontest2, "Another test option"
end.add_option_processor do |opts|
run = true if opts.present?(:optiontest)
end.add_option_processor do |opts|
run2 = true if opts.present?(:optiontest2)
end.parse_options(["--optiontest", "--optiontest2"])
run.should == true
run2.should == true
end
end
end
|