boson 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +76 -0
- data/README.rdoc +6 -6
- data/Rakefile +24 -41
- data/gemspec +19 -0
- data/lib/boson.rb +4 -4
- data/lib/boson/command.rb +2 -2
- data/lib/boson/commands/core.rb +1 -1
- data/lib/boson/commands/web_core.rb +16 -12
- data/lib/boson/manager.rb +1 -1
- data/lib/boson/pipes.rb +6 -2
- data/lib/boson/repo_index.rb +1 -1
- data/lib/boson/runner.rb +2 -2
- data/lib/boson/runners/bin_runner.rb +72 -29
- data/lib/boson/scientist.rb +22 -4
- data/lib/boson/util.rb +9 -1
- data/lib/boson/version.rb +3 -0
- data/test/argument_inspector_test.rb +47 -51
- data/test/bacon_extensions.rb +26 -0
- data/test/bin_runner_test.rb +160 -160
- data/test/comment_inspector_test.rb +87 -89
- data/test/file_library_test.rb +32 -34
- data/test/loader_test.rb +181 -182
- data/test/manager_test.rb +76 -78
- data/test/method_inspector_test.rb +51 -53
- data/test/option_parser_test.rb +49 -42
- data/test/options_test.rb +168 -168
- data/test/pipes_test.rb +48 -46
- data/test/repo_index_test.rb +117 -113
- data/test/repo_test.rb +17 -17
- data/test/runner_test.rb +31 -34
- data/test/scientist_test.rb +258 -254
- data/test/test_helper.rb +21 -38
- data/test/util_test.rb +40 -42
- metadata +55 -46
- data/VERSION.yml +0 -5
data/test/options_test.rb
CHANGED
@@ -1,189 +1,189 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
describe "Options" do
|
4
|
+
def create(opts)
|
5
|
+
@opt = OptionParser.new(opts)
|
6
|
+
end
|
7
|
+
|
8
|
+
def parse(*args)
|
9
|
+
@non_opts = []
|
10
|
+
@opt.parse(args.flatten)
|
11
|
+
end
|
6
12
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
13
|
+
describe ":string type" do
|
14
|
+
before {
|
15
|
+
create "--foo" => :string, "--bar" => :string, :blah=>{:type=>:string, :default=>:huh}
|
16
|
+
}
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
|
18
|
+
it "doesn't set nonexistant options" do
|
19
|
+
parse("--bling")[:bar].should == nil
|
20
|
+
end
|
15
21
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
it "sets values correctly" do
|
23
|
+
parse("--foo", "12")[:foo].should == "12"
|
24
|
+
parse("--bar", "12")[:bar].should == "12"
|
25
|
+
end
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
27
|
+
it "raises error if passed another valid option" do
|
28
|
+
assert_error(OptionParser::Error, "cannot pass.*'foo'") { parse("--foo", "--bar") }
|
29
|
+
end
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
31
|
+
it "raises error if not passed a value" do
|
32
|
+
assert_error(OptionParser::Error, "no value.*'foo'") { parse("--foo") }
|
33
|
+
end
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
it "overwrites earlier values with later values" do
|
36
|
+
parse("--foo", "12", "--foo", "13")[:foo].should == "13"
|
37
|
+
end
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
it "can have symbolic default value" do
|
40
|
+
parse('--blah','ok')[:blah].should == 'ok'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ":string type with :values attribute" do
|
45
|
+
before_all { create :foo=>{:type=>:string, :values=>%w{angola abu abib}} }
|
46
|
+
it "auto aliases if a match exists" do
|
47
|
+
parse("-f", "an")[:foo].should == 'angola'
|
36
48
|
end
|
37
|
-
|
38
|
-
context ":string type with :values attribute" do
|
39
|
-
before(:all ) { create :foo=>{:type=>:string, :values=>%w{angola abu abib}} }
|
40
|
-
it "auto aliases if a match exists" do
|
41
|
-
parse("-f", "an")[:foo].should == 'angola'
|
42
|
-
end
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
50
|
+
it "auto aliases first sorted match" do
|
51
|
+
parse("-f", "a")[:foo].should == 'abib'
|
52
|
+
end
|
47
53
|
|
48
|
-
|
49
|
-
|
50
|
-
|
54
|
+
it "raises error if option doesn't auto alias or match given values" do
|
55
|
+
assert_error(OptionParser::Error, "invalid.*'z'") { parse("-f", "z") }
|
56
|
+
end
|
51
57
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
58
|
+
it "doesn't raise error for a nonmatch if enum is false" do
|
59
|
+
create :foo=>{:type=>:string, :values=>%w{angola abu abib}, :enum=>false}
|
60
|
+
parse("-f", "z")[:foo].should == 'z'
|
56
61
|
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe ":string type with default value" do
|
65
|
+
before { create "--branch" => "master" }
|
57
66
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
67
|
+
it "should get the specified value" do
|
68
|
+
parse("--branch", "bugfix").should == { :branch => "bugfix" }
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should get the default value when not specified" do
|
72
|
+
parse.should == { :branch => "master" }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe ":numeric type" do
|
77
|
+
before { create "n" => :numeric, "m" => 5 }
|
78
|
+
|
79
|
+
it "supports numeric defaults" do
|
80
|
+
parse["m"].should == 5
|
81
|
+
end
|
82
|
+
|
83
|
+
it "converts values to numeric types" do
|
84
|
+
parse("-n", "3", "-m", ".5").should == {:n => 3, :m => 0.5}
|
85
|
+
end
|
66
86
|
|
67
|
-
|
68
|
-
|
69
|
-
end
|
87
|
+
it "raises error when value isn't numeric" do
|
88
|
+
assert_error(OptionParser::Error, "expected numeric value for.*'n'") { parse("-n", "foo") }
|
70
89
|
end
|
71
90
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
context ":array type" do
|
95
|
-
before(:all) {
|
96
|
-
create :a=>:array, :b=>[1,2,3], :c=>{:type=>:array, :values=>%w{foo fa bar zebra}, :enum=>false},
|
97
|
-
:d=>{:type=>:array, :split=>" ", :values=>[:ab, :bc, :cd], :enum=>false},
|
98
|
-
:e=>{:type=>:array, :values=>%w{some so silly}, :regexp=>true}
|
99
|
-
}
|
100
|
-
|
101
|
-
it "supports array defaults" do
|
102
|
-
parse[:b].should == [1,2,3]
|
103
|
-
end
|
104
|
-
|
105
|
-
it "converts comma delimited values to an array" do
|
106
|
-
parse("-a","1,2,5")[:a].should == %w{1 2 5}
|
107
|
-
end
|
108
|
-
|
109
|
-
it "raises error when option has no value" do
|
110
|
-
assert_error(OptionParser::Error, "no value.*'a'") { parse("-a") }
|
111
|
-
end
|
112
|
-
|
113
|
-
it "auto aliases :values attribute" do
|
114
|
-
parse("-c","f,b")[:c].should == %w{fa bar}
|
115
|
-
end
|
116
|
-
|
117
|
-
it "auto aliases symbolic :values" do
|
118
|
-
parse("-d","a c")[:d].should == [:ab,:cd]
|
119
|
-
end
|
120
|
-
|
121
|
-
it "supports a configurable splitter" do
|
122
|
-
parse("-d", "yogi berra")[:d].should == %w{yogi berra}
|
123
|
-
end
|
124
|
-
|
125
|
-
it "aliases * to all values" do
|
126
|
-
parse("-c", '*')[:c].sort.should == %w{bar fa foo zebra}
|
127
|
-
parse("-c", '*,ok')[:c].sort.should == %w{bar fa foo ok zebra}
|
128
|
-
end
|
129
|
-
|
130
|
-
it "aliases correctly with :regexp on" do
|
131
|
-
parse("-e", 'so')[:e].sort.should == %w{so some}
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context ":hash type" do
|
136
|
-
before(:all) {
|
137
|
-
create :a=>:hash, :b=>{:default=>{:a=>'b'}}, :c=>{:type=>:hash, :keys=>%w{one two three}},
|
138
|
-
:e=>{:type=>:hash, :keys=>[:one, :two, :three], :default_keys=>:three},
|
139
|
-
:d=>{:type=>:hash, :split=>" "}
|
140
|
-
}
|
141
|
-
|
142
|
-
it "converts comma delimited pairs to hash" do
|
143
|
-
parse("-a", "f:3,g:4")[:a].should == {'f'=>'3', 'g'=>'4'}
|
144
|
-
end
|
145
|
-
|
146
|
-
it "supports hash defaults" do
|
147
|
-
parse[:b].should == {:a=>'b'}
|
148
|
-
end
|
149
|
-
|
150
|
-
it "raises error when option has no value" do
|
151
|
-
assert_error(OptionParser::Error, "no value.*'a'") { parse("-a") }
|
152
|
-
end
|
153
|
-
|
154
|
-
it "raises error if invalid key-value pair given for unknown keys" do
|
155
|
-
assert_error(OptionParser::Error, "invalid.*pair.*'a'") { parse("-a", 'b') }
|
156
|
-
end
|
157
|
-
|
158
|
-
it "auto aliases :keys attribute" do
|
159
|
-
parse("-c","t:3,o:1")[:c].should == {'three'=>'3', 'one'=>'1'}
|
160
|
-
end
|
161
|
-
|
162
|
-
it "adds in explicit default keys with value only argument" do
|
163
|
-
parse('-e', 'whoop')[:e].should == {:three=>'whoop'}
|
164
|
-
end
|
165
|
-
|
166
|
-
it "adds in default keys from known :keys with value only argument" do
|
167
|
-
parse("-c","okay")[:c].should == {'one'=>'okay'}
|
168
|
-
end
|
169
|
-
|
170
|
-
it "auto aliases symbolic :keys" do
|
171
|
-
parse("-e","t:3,o:1")[:e].should == {:three=>'3', :one=>'1'}
|
172
|
-
end
|
173
|
-
|
174
|
-
it "supports a configurable splitter" do
|
175
|
-
parse("-d","a:ab b:bc")[:d].should == {'a'=>'ab', 'b'=>'bc'}
|
176
|
-
end
|
177
|
-
|
178
|
-
it "supports grouping keys" do
|
179
|
-
parse("-c", "t,tw:foo,o:bar")[:c].should == {'three'=>'foo','two'=>'foo', 'one'=>'bar'}
|
180
|
-
end
|
181
|
-
|
182
|
-
it "aliases * to all keys" do
|
183
|
-
parse("-c", "*:foo")[:c].should == {'three'=>'foo', 'two'=>'foo', 'one'=>'foo'}
|
184
|
-
parse('-a', '*:foo')[:a].should == {'*'=>'foo'}
|
185
|
-
end
|
91
|
+
it "raises error when opt is present without value" do
|
92
|
+
assert_error(OptionParser::Error, "no value.*'n'") { parse("-n") }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe ":array type" do
|
97
|
+
before_all {
|
98
|
+
create :a=>:array, :b=>[1,2,3], :c=>{:type=>:array, :values=>%w{foo fa bar zebra}, :enum=>false},
|
99
|
+
:d=>{:type=>:array, :split=>" ", :values=>[:ab, :bc, :cd], :enum=>false},
|
100
|
+
:e=>{:type=>:array, :values=>%w{some so silly}, :regexp=>true}
|
101
|
+
}
|
102
|
+
|
103
|
+
it "supports array defaults" do
|
104
|
+
parse[:b].should == [1,2,3]
|
105
|
+
end
|
106
|
+
|
107
|
+
it "converts comma delimited values to an array" do
|
108
|
+
parse("-a","1,2,5")[:a].should == %w{1 2 5}
|
109
|
+
end
|
110
|
+
|
111
|
+
it "raises error when option has no value" do
|
112
|
+
assert_error(OptionParser::Error, "no value.*'a'") { parse("-a") }
|
186
113
|
end
|
187
114
|
|
115
|
+
it "auto aliases :values attribute" do
|
116
|
+
parse("-c","f,b")[:c].should == %w{fa bar}
|
117
|
+
end
|
118
|
+
|
119
|
+
it "auto aliases symbolic :values" do
|
120
|
+
parse("-d","a c")[:d].should == [:ab,:cd]
|
121
|
+
end
|
122
|
+
|
123
|
+
it "supports a configurable splitter" do
|
124
|
+
parse("-d", "yogi berra")[:d].should == %w{yogi berra}
|
125
|
+
end
|
126
|
+
|
127
|
+
it "aliases * to all values" do
|
128
|
+
parse("-c", '*')[:c].sort.should == %w{bar fa foo zebra}
|
129
|
+
parse("-c", '*,ok')[:c].sort.should == %w{bar fa foo ok zebra}
|
130
|
+
end
|
131
|
+
|
132
|
+
it "aliases correctly with :regexp on" do
|
133
|
+
parse("-e", 'so')[:e].sort.should == %w{so some}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe ":hash type" do
|
138
|
+
before_all {
|
139
|
+
create :a=>:hash, :b=>{:default=>{:a=>'b'}}, :c=>{:type=>:hash, :keys=>%w{one two three}},
|
140
|
+
:e=>{:type=>:hash, :keys=>[:one, :two, :three], :default_keys=>:three},
|
141
|
+
:d=>{:type=>:hash, :split=>" "}
|
142
|
+
}
|
143
|
+
|
144
|
+
it "converts comma delimited pairs to hash" do
|
145
|
+
parse("-a", "f:3,g:4")[:a].should == {'f'=>'3', 'g'=>'4'}
|
146
|
+
end
|
147
|
+
|
148
|
+
it "supports hash defaults" do
|
149
|
+
parse[:b].should == {:a=>'b'}
|
150
|
+
end
|
151
|
+
|
152
|
+
it "raises error when option has no value" do
|
153
|
+
assert_error(OptionParser::Error, "no value.*'a'") { parse("-a") }
|
154
|
+
end
|
155
|
+
|
156
|
+
it "raises error if invalid key-value pair given for unknown keys" do
|
157
|
+
assert_error(OptionParser::Error, "invalid.*pair.*'a'") { parse("-a", 'b') }
|
158
|
+
end
|
159
|
+
|
160
|
+
it "auto aliases :keys attribute" do
|
161
|
+
parse("-c","t:3,o:1")[:c].should == {'three'=>'3', 'one'=>'1'}
|
162
|
+
end
|
163
|
+
|
164
|
+
it "adds in explicit default keys with value only argument" do
|
165
|
+
parse('-e', 'whoop')[:e].should == {:three=>'whoop'}
|
166
|
+
end
|
167
|
+
|
168
|
+
it "adds in default keys from known :keys with value only argument" do
|
169
|
+
parse("-c","okay")[:c].should == {'one'=>'okay'}
|
170
|
+
end
|
171
|
+
|
172
|
+
it "auto aliases symbolic :keys" do
|
173
|
+
parse("-e","t:3,o:1")[:e].should == {:three=>'3', :one=>'1'}
|
174
|
+
end
|
175
|
+
|
176
|
+
it "supports a configurable splitter" do
|
177
|
+
parse("-d","a:ab b:bc")[:d].should == {'a'=>'ab', 'b'=>'bc'}
|
178
|
+
end
|
179
|
+
|
180
|
+
it "supports grouping keys" do
|
181
|
+
parse("-c", "t,tw:foo,o:bar")[:c].should == {'three'=>'foo','two'=>'foo', 'one'=>'bar'}
|
182
|
+
end
|
183
|
+
|
184
|
+
it "aliases * to all keys" do
|
185
|
+
parse("-c", "*:foo")[:c].should == {'three'=>'foo', 'two'=>'foo', 'one'=>'foo'}
|
186
|
+
parse('-a', '*:foo')[:a].should == {'*'=>'foo'}
|
187
|
+
end
|
188
188
|
end
|
189
|
-
end
|
189
|
+
end
|
data/test/pipes_test.rb
CHANGED
@@ -1,54 +1,56 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
describe "Pipes" do
|
4
|
+
before_all { ::Ab = Struct.new(:a, :b) }
|
5
|
+
describe "query_pipe" do
|
6
|
+
before_all {
|
6
7
|
@hashes = [{:a=>'some', :b=>'thing'}, {:a=>:more, :b=>:yep}]
|
7
|
-
Ab = Struct.new(:a, :b) unless PipeTest.const_defined?(:Ab)
|
8
8
|
@objects = [Ab.new('some', 'thing'), Ab.new(:more, :yep)]
|
9
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
|
-
|
10
|
+
|
11
|
+
it "searches one query" do
|
12
|
+
[@hashes, @objects].each {|e|
|
13
|
+
Pipes.query_pipe(e, :a=>'some').should == e[0,1]
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "searches non-string values" do
|
18
|
+
[@hashes, @objects].each {|e|
|
19
|
+
Pipes.query_pipe(e, :a=>'more').should == e[1,1]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
it "searches multiple search terms" do
|
24
|
+
[@hashes, @objects].each {|e|
|
25
|
+
Pipes.query_pipe(e, :a=>'some', :b=>'yep').size.should == 2
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "prints error for invalid search field" do
|
30
|
+
capture_stderr { Pipes.query_pipe(@objects, :blah=>'blah') }.should =~ /failed.*'blah'/
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "sort_pipe" do
|
35
|
+
before_all {
|
36
|
+
@hashes = [{:a=>'some', :b=>'thing'}, {:a=>:more, :b=>:yep}]
|
37
|
+
@objects = [Ab.new('some', 'thing'), Ab.new(:more, :yep)]
|
38
|
+
}
|
39
|
+
it "sorts objects with values of different types" do
|
40
|
+
Pipes.sort_pipe(@objects, :a).should == @objects.reverse
|
41
|
+
end
|
42
|
+
|
43
|
+
it "sorts hashes with values of different types" do
|
44
|
+
Pipes.sort_pipe(@hashes, :a).should == @hashes.reverse
|
45
|
+
end
|
46
|
+
|
47
|
+
it "sorts numeric values" do
|
48
|
+
hashes = [{:a=>10, :b=>4}, {:a=>5, :b=>3}]
|
49
|
+
Pipes.sort_pipe(hashes, :a).should == hashes.reverse
|
50
|
+
end
|
51
|
+
|
52
|
+
it "prints error for invalid sort field" do
|
53
|
+
capture_stderr { Pipes.sort_pipe(@objects, :blah)}.should =~ /failed.*'blah'/
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|