boson 0.1.0 → 0.2.0
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/README.rdoc +15 -3
- data/Rakefile +2 -2
- data/VERSION.yml +1 -1
- data/lib/boson.rb +22 -4
- data/lib/boson/command.rb +12 -4
- data/lib/boson/commands/core.rb +19 -19
- data/lib/boson/commands/web_core.rb +18 -5
- data/lib/boson/index.rb +31 -22
- data/lib/boson/inspector.rb +12 -10
- data/lib/boson/inspectors/method_inspector.rb +1 -1
- data/lib/boson/libraries/file_library.rb +31 -11
- data/lib/boson/libraries/gem_library.rb +6 -0
- data/lib/boson/libraries/module_library.rb +24 -4
- data/lib/boson/libraries/require_library.rb +8 -0
- data/lib/boson/library.rb +75 -35
- data/lib/boson/loader.rb +41 -12
- data/lib/boson/manager.rb +19 -14
- data/lib/boson/option_parser.rb +144 -107
- data/lib/boson/options.rb +127 -0
- data/lib/boson/repo.rb +25 -6
- data/lib/boson/runner.rb +2 -2
- data/lib/boson/runners/bin_runner.rb +25 -15
- data/lib/boson/scientist.rb +98 -28
- data/lib/boson/util.rb +20 -14
- data/lib/boson/view.rb +70 -15
- data/test/bin_runner_test.rb +27 -11
- data/test/file_library_test.rb +14 -1
- data/test/index_test.rb +2 -1
- data/test/loader_test.rb +84 -21
- data/test/manager_test.rb +1 -9
- data/test/method_inspector_test.rb +2 -2
- data/test/option_parser_test.rb +176 -20
- data/test/repo_test.rb +1 -0
- data/test/scientist_test.rb +38 -2
- data/test/test_helper.rb +6 -3
- data/test/view_test.rb +58 -0
- metadata +7 -6
- data/test/commands_test.rb +0 -51
data/test/repo_test.rb
CHANGED
@@ -11,6 +11,7 @@ class Boson::RepoTest < Test::Unit::TestCase
|
|
11
11
|
|
12
12
|
test "reads existing config correctly" do
|
13
13
|
expected_hash = {:commands=>{'c1'=>{}}, :libraries=>{}}
|
14
|
+
File.expects(:exists?).returns(true)
|
14
15
|
YAML.expects(:load_file).returns(expected_hash)
|
15
16
|
@repo.config[:commands]['c1'].should == {}
|
16
17
|
end
|
data/test/scientist_test.rb
CHANGED
@@ -3,6 +3,8 @@ require File.join(File.dirname(__FILE__), 'test_helper')
|
|
3
3
|
module Boson
|
4
4
|
class ScientistTest < Test::Unit::TestCase
|
5
5
|
before(:all) {
|
6
|
+
unless ScientistTest.const_defined?(:Blah)
|
7
|
+
Boson.send :remove_const, :BinRunner if Boson.const_defined?(:BinRunner)
|
6
8
|
eval <<-EOF
|
7
9
|
module Blah
|
8
10
|
def blah(arg1, options={})
|
@@ -15,8 +17,12 @@ module Boson
|
|
15
17
|
[arg1, arg2, options]
|
16
18
|
end
|
17
19
|
def default; 'some default'; end
|
20
|
+
def default_option(options={})
|
21
|
+
options
|
22
|
+
end
|
18
23
|
end
|
19
24
|
EOF
|
25
|
+
end
|
20
26
|
@opt_cmd = Object.new.extend Blah
|
21
27
|
}
|
22
28
|
|
@@ -126,7 +132,7 @@ module Boson
|
|
126
132
|
end
|
127
133
|
|
128
134
|
test "with unexpected error in translation" do
|
129
|
-
Scientist.expects(:
|
135
|
+
Scientist.expects(:parse_command_options).raises("unexpected")
|
130
136
|
capture_stderr { command_with_args('a1') }.should =~ /Error.*unexpected/
|
131
137
|
end
|
132
138
|
|
@@ -187,7 +193,7 @@ module Boson
|
|
187
193
|
end
|
188
194
|
|
189
195
|
def render_expected(options=nil)
|
190
|
-
View.expects(:render).with(anything, options || anything)
|
196
|
+
View.expects(:render).with(anything, options || anything, false)
|
191
197
|
end
|
192
198
|
|
193
199
|
context "render" do
|
@@ -238,6 +244,36 @@ module Boson
|
|
238
244
|
end
|
239
245
|
end
|
240
246
|
|
247
|
+
context "command with default option" do
|
248
|
+
before(:all) { @cmd_attributes = {:name=>'default_option', :default_option=>'level', :args=>1} }
|
249
|
+
|
250
|
+
test "parses normally from irb" do
|
251
|
+
command(@cmd_attributes, '-f --level=3').should == {:level=>3, :force=>true}
|
252
|
+
end
|
253
|
+
|
254
|
+
test "parses normally from cmdline" do
|
255
|
+
Boson.expects(:const_defined?).returns true
|
256
|
+
command(@cmd_attributes, ['--force', '--level=3']).should == {:level=>3, :force=>true}
|
257
|
+
end
|
258
|
+
|
259
|
+
test "parses no arguments normally" do
|
260
|
+
command(@cmd_attributes, '').should == {:level=>2}
|
261
|
+
end
|
262
|
+
|
263
|
+
test "parses ruby arguments normally" do
|
264
|
+
command(@cmd_attributes, [{:force=>true, :level=>10}]).should == {:level=>10, :force=>true}
|
265
|
+
end
|
266
|
+
|
267
|
+
test "prepends correctly from irb" do
|
268
|
+
command(@cmd_attributes, '3 -f').should == {:level=>3, :force=>true}
|
269
|
+
end
|
270
|
+
|
271
|
+
test "prepends correctly from cmdline" do
|
272
|
+
Boson.expects(:const_defined?).returns true
|
273
|
+
command(@cmd_attributes, ['3','-f']).should == {:level=>3, :force=>true}
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
241
277
|
test "optionless command renders" do
|
242
278
|
render_expected :fields=>['f1']
|
243
279
|
command({:args=>2, :options=>nil, :render_options=>{:fields=>:array}}, ["--fields f1 ab ok"])
|
data/test/test_helper.rb
CHANGED
@@ -21,6 +21,8 @@ require 'test_benchmark' if ENV['BENCHMARK']
|
|
21
21
|
class Test::Unit::TestCase
|
22
22
|
# make local so it doesn't pick up my real boson dir
|
23
23
|
Boson.repo.dir = File.dirname(__FILE__)
|
24
|
+
# prevent extra File.exists? calls which interfere with stubs for it
|
25
|
+
Boson.repo.config = {:libraries=>{}, :command_aliases=>{}, :console_defaults=>[]}
|
24
26
|
Boson.instance_variable_set "@repos", [Boson.repo]
|
25
27
|
|
26
28
|
def assert_error(error, message=nil)
|
@@ -54,7 +56,7 @@ class Test::Unit::TestCase
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def command_exists?(name, bool=true)
|
57
|
-
!!Boson::Command.find(name).should == bool
|
59
|
+
(!!Boson::Command.find(name)).should == bool
|
58
60
|
end
|
59
61
|
|
60
62
|
def library_loaded?(name, bool=true)
|
@@ -77,8 +79,9 @@ class Test::Unit::TestCase
|
|
77
79
|
|
78
80
|
# mocks as a file library
|
79
81
|
def mock_library(lib, options={})
|
80
|
-
options
|
81
|
-
File.expects(:exists?).with(Boson::FileLibrary.library_file(lib.to_s, Boson.repo.dir)).
|
82
|
+
options = {:file_string=>'', :exists=>true}.merge!(options)
|
83
|
+
File.expects(:exists?).with(Boson::FileLibrary.library_file(lib.to_s, Boson.repo.dir)).
|
84
|
+
at_least(1).returns(options.delete(:exists))
|
82
85
|
File.expects(:read).returns(options.delete(:file_string))
|
83
86
|
end
|
84
87
|
|
data/test/view_test.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
module Boson
|
4
|
+
class ViewTest < Test::Unit::TestCase
|
5
|
+
before(:all) {
|
6
|
+
@hashes = [{:a=>'some', :b=>'thing'}, {:a=>:more, :b=>:yep}]
|
7
|
+
Ab = Struct.new(:a, :b) unless ViewTest.const_defined?(:Ab)
|
8
|
+
@objects = [Ab.new('some', 'thing'), Ab.new(:more, :yep)]
|
9
|
+
}
|
10
|
+
context "search_object" do
|
11
|
+
|
12
|
+
test "searches one query" do
|
13
|
+
[@hashes, @objects].each {|e|
|
14
|
+
View.search_object(e, :a=>'some').should == e[0,1]
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
test "searches non-string values" do
|
19
|
+
[@hashes, @objects].each {|e|
|
20
|
+
View.search_object(e, :a=>'more').should == e[1,1]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
test "searches multiple search terms" do
|
25
|
+
[@hashes, @objects].each {|e|
|
26
|
+
View.search_object(e, :a=>'some', :b=>'yep').size.should == 2
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
test "prints error for invalid search field" do
|
31
|
+
capture_stderr { View.search_object(@objects, :blah=>'blah') }.should =~ /failed.*'blah'/
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "sort_object" do
|
36
|
+
test "sorts objects with values of different types" do
|
37
|
+
View.sort_object(@objects, :a).should == @objects.reverse
|
38
|
+
end
|
39
|
+
|
40
|
+
test "sorts hashes with values of different types" do
|
41
|
+
View.sort_object(@hashes, :a).should == @hashes.reverse
|
42
|
+
end
|
43
|
+
|
44
|
+
test "sorts numeric values" do
|
45
|
+
hashes = [{:a=>10, :b=>4}, {:a=>5, :b=>3}]
|
46
|
+
View.sort_object(hashes, :a).should == hashes.reverse
|
47
|
+
end
|
48
|
+
|
49
|
+
test "sorts and reverses sort" do
|
50
|
+
View.sort_object(@hashes, :a, true).should == @hashes
|
51
|
+
end
|
52
|
+
|
53
|
+
test "prints error for invalid sort field" do
|
54
|
+
capture_stderr { View.sort_object(@objects, :blah)}.should =~ /failed.*'blah'/
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Horner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-07 00:00:00 -05:00
|
13
13
|
default_executable: boson
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.2.
|
23
|
+
version: 0.2.8
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: alias
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/boson/manager.rb
|
67
67
|
- lib/boson/namespace.rb
|
68
68
|
- lib/boson/option_parser.rb
|
69
|
+
- lib/boson/options.rb
|
69
70
|
- lib/boson/repo.rb
|
70
71
|
- lib/boson/runner.rb
|
71
72
|
- lib/boson/runners/bin_runner.rb
|
@@ -75,7 +76,6 @@ files:
|
|
75
76
|
- lib/boson/view.rb
|
76
77
|
- test/argument_inspector_test.rb
|
77
78
|
- test/bin_runner_test.rb
|
78
|
-
- test/commands_test.rb
|
79
79
|
- test/comment_inspector_test.rb
|
80
80
|
- test/file_library_test.rb
|
81
81
|
- test/index_test.rb
|
@@ -87,8 +87,9 @@ files:
|
|
87
87
|
- test/runner_test.rb
|
88
88
|
- test/scientist_test.rb
|
89
89
|
- test/test_helper.rb
|
90
|
+
- test/view_test.rb
|
90
91
|
has_rdoc: true
|
91
|
-
homepage: http://
|
92
|
+
homepage: http://tagaholic.me/boson/
|
92
93
|
licenses: []
|
93
94
|
|
94
95
|
post_install_message:
|
@@ -118,7 +119,6 @@ summary: Boson provides users with the power to turn any ruby method into a full
|
|
118
119
|
test_files:
|
119
120
|
- test/argument_inspector_test.rb
|
120
121
|
- test/bin_runner_test.rb
|
121
|
-
- test/commands_test.rb
|
122
122
|
- test/comment_inspector_test.rb
|
123
123
|
- test/file_library_test.rb
|
124
124
|
- test/index_test.rb
|
@@ -130,3 +130,4 @@ test_files:
|
|
130
130
|
- test/runner_test.rb
|
131
131
|
- test/scientist_test.rb
|
132
132
|
- test/test_helper.rb
|
133
|
+
- test/view_test.rb
|
data/test/commands_test.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
module Boson
|
4
|
-
class CommandsTest < Test::Unit::TestCase
|
5
|
-
before(:all) {
|
6
|
-
reset_boson
|
7
|
-
@higgs = Boson.main_object
|
8
|
-
ancestors = class <<Boson.main_object; self end.ancestors
|
9
|
-
# allows running just this test file
|
10
|
-
Manager.load Runner.default_libraries unless ancestors.include?(Boson::Commands::Core)
|
11
|
-
}
|
12
|
-
|
13
|
-
def render_expects(&block)
|
14
|
-
View.expects(:render).with(&block)
|
15
|
-
end
|
16
|
-
|
17
|
-
context "libraries" do
|
18
|
-
before(:all) {
|
19
|
-
Boson.libraries << Boson::Library.new(:name=>'blah')
|
20
|
-
Boson.libraries << Boson::Library.new(:name=>'another', :module=>"Cool")
|
21
|
-
}
|
22
|
-
|
23
|
-
test "lists all when given no argument" do
|
24
|
-
render_expects {|*args| args[0].size == 2}
|
25
|
-
@higgs.libraries
|
26
|
-
end
|
27
|
-
|
28
|
-
test "searches with a given search field" do
|
29
|
-
render_expects {|*args| args[0] == [Boson.library('another')]}
|
30
|
-
@higgs.libraries('Cool', :query_fields=>[:module])
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "commands" do
|
35
|
-
before(:all) {
|
36
|
-
Boson.commands << Command.create('some', Library.new(:name=>'thing'))
|
37
|
-
Boson.commands << Command.create('and', Library.new(:name=>'this'))
|
38
|
-
}
|
39
|
-
|
40
|
-
test "lists all when given no argument" do
|
41
|
-
render_expects {|*args| args[0].size == 2}
|
42
|
-
@higgs.commands
|
43
|
-
end
|
44
|
-
|
45
|
-
test "searches with a given search field" do
|
46
|
-
render_expects {|*args| args[0] == [Command.find('and')]}
|
47
|
-
@higgs.commands('this', :query_fields=>[:lib])
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|