boson 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,100 +1,98 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
CommentInspector.scrape(@lines.join("\n"), options[:line] || 3, Optional)[:desc]
|
12
|
-
end
|
13
|
-
|
14
|
-
test "directly above method returns desc" do
|
15
|
-
description.should == "some comments yay"
|
16
|
-
end
|
17
|
-
|
18
|
-
test "with explicit @desc returns desc" do
|
19
|
-
@lines[1] = '#@desc some comments yay'
|
20
|
-
description.should == "some comments yay"
|
21
|
-
end
|
22
|
-
|
23
|
-
test "of multiple lines returns desc" do
|
24
|
-
@lines.delete_at(1)
|
25
|
-
@lines.insert(1, '#@options :b=>1', '#@desc here be', '# comments')
|
26
|
-
description(:line=>5).should == "here be comments"
|
27
|
-
end
|
28
|
-
|
29
|
-
test "that is empty returns nil" do
|
30
|
-
@lines[1] = ""
|
31
|
-
description.should == nil
|
32
|
-
end
|
33
|
-
|
34
|
-
test "that is empty with options keyword returns nil" do
|
35
|
-
@lines[1] = '#@options {:a=>1}'
|
36
|
-
description.should == nil
|
37
|
-
end
|
38
|
-
|
39
|
-
test "not directly above returns nil" do
|
40
|
-
@lines.insert(2, " ")
|
41
|
-
description(:line=>4).should == nil
|
42
|
-
end
|
3
|
+
describe "CommentInspector" do
|
4
|
+
before_all { eval "module ::Optional; def self.bling; {:a=>'bling'}; end; end" }
|
5
|
+
describe "scrapes description" do
|
6
|
+
before {
|
7
|
+
@lines = ["module Foo", " # some comments yay", " def foo", " end", "end"]
|
8
|
+
}
|
9
|
+
def description(options={})
|
10
|
+
CommentInspector.scrape(@lines.join("\n"), options[:line] || 3, Optional)[:desc]
|
43
11
|
end
|
44
12
|
|
45
|
-
|
46
|
-
|
47
|
-
@lines = ["module Foo", ' #@options {:a=>true}', " def foo", " end", "end"]
|
48
|
-
}
|
49
|
-
def options(opts={})
|
50
|
-
@lines[1] = opts[:value] if opts[:value]
|
51
|
-
args = [@lines.join("\n"), 3, Optional]
|
52
|
-
CommentInspector.scrape(*args)[:options]
|
53
|
-
end
|
54
|
-
|
55
|
-
test "that are basic return options" do
|
56
|
-
options.should == {:a=>true}
|
57
|
-
end
|
58
|
-
|
59
|
-
test "that are hash-like returns hashified options" do
|
60
|
-
options(:value=>'#@options :a => 2').should == {:a=>2}
|
61
|
-
end
|
62
|
-
|
63
|
-
test "that are whitespaced return options" do
|
64
|
-
options(:value=>"\t"+ '# @options {:a=>1}').should == {:a=>1}
|
65
|
-
end
|
66
|
-
|
67
|
-
test "that have a local value return options" do
|
68
|
-
options(:value=>'#@options bling').should == {:a=>'bling'}
|
69
|
-
end
|
70
|
-
|
71
|
-
test "that are multi-line return options" do
|
72
|
-
@lines.delete_at(1)
|
73
|
-
@lines.insert(1, '#@options {:a =>', " # 1}", "# some comments")
|
74
|
-
CommentInspector.scrape(@lines.join("\n"), 5, Optional)[:options].should == {:a=>1}
|
75
|
-
end
|
76
|
-
|
77
|
-
test "with failed eval return nil" do
|
78
|
-
options(:value=>'#@options !--').should == nil
|
79
|
-
end
|
80
|
-
|
81
|
-
test "that are empty return nil" do
|
82
|
-
options(:value=>"# nada").should == nil
|
83
|
-
end
|
13
|
+
it "directly above method returns desc" do
|
14
|
+
description.should == "some comments yay"
|
84
15
|
end
|
85
16
|
|
86
|
-
|
87
|
-
@lines =
|
88
|
-
|
89
|
-
expected = {:desc=>"blah", :options=>{:a=>true}, :render_options=>{:b=>1}, :config=>{:a=>true}}
|
90
|
-
CommentInspector.scrape(@lines.join("\n"), 6, Optional).should == expected
|
17
|
+
it "with explicit @desc returns desc" do
|
18
|
+
@lines[1] = '#@desc some comments yay'
|
19
|
+
description.should == "some comments yay"
|
91
20
|
end
|
92
21
|
|
93
|
-
|
94
|
-
@lines
|
95
|
-
|
96
|
-
|
97
|
-
CommentInspector.scrape(@lines.join("\n"), 7, Optional).should == expected
|
22
|
+
it "of multiple lines returns desc" do
|
23
|
+
@lines.delete_at(1)
|
24
|
+
@lines.insert(1, '#@options :b=>1', '#@desc here be', '# comments')
|
25
|
+
description(:line=>5).should == "here be comments"
|
98
26
|
end
|
27
|
+
|
28
|
+
it "that is empty returns nil" do
|
29
|
+
@lines[1] = ""
|
30
|
+
description.should == nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it "that is empty with options keyword returns nil" do
|
34
|
+
@lines[1] = '#@options {:a=>1}'
|
35
|
+
description.should == nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it "not directly above returns nil" do
|
39
|
+
@lines.insert(2, " ")
|
40
|
+
description(:line=>4).should == nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "scrapes options" do
|
45
|
+
before {
|
46
|
+
@lines = ["module Foo", ' #@options {:a=>true}', " def foo", " end", "end"]
|
47
|
+
}
|
48
|
+
def options(opts={})
|
49
|
+
@lines[1] = opts[:value] if opts[:value]
|
50
|
+
args = [@lines.join("\n"), 3, Optional]
|
51
|
+
CommentInspector.scrape(*args)[:options]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "that are basic return options" do
|
55
|
+
options.should == {:a=>true}
|
56
|
+
end
|
57
|
+
|
58
|
+
it "that are hash-like returns hashified options" do
|
59
|
+
options(:value=>'#@options :a => 2').should == {:a=>2}
|
60
|
+
end
|
61
|
+
|
62
|
+
it "that are whitespaced return options" do
|
63
|
+
options(:value=>"\t"+ '# @options {:a=>1}').should == {:a=>1}
|
64
|
+
end
|
65
|
+
|
66
|
+
it "that have a local value return options" do
|
67
|
+
options(:value=>'#@options bling').should == {:a=>'bling'}
|
68
|
+
end
|
69
|
+
|
70
|
+
it "that are multi-line return options" do
|
71
|
+
@lines.delete_at(1)
|
72
|
+
@lines.insert(1, '#@options {:a =>', " # 1}", "# some comments")
|
73
|
+
CommentInspector.scrape(@lines.join("\n"), 5, Optional)[:options].should == {:a=>1}
|
74
|
+
end
|
75
|
+
|
76
|
+
it "with failed eval return nil" do
|
77
|
+
options(:value=>'#@options !--').should == nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it "that are empty return nil" do
|
81
|
+
options(:value=>"# nada").should == nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "scrapes all comment types with implicit desc" do
|
86
|
+
@lines = ["module Foo", '# @config :a=>true', '# @render_options :b=>1', ' # @options {:a=>true}',
|
87
|
+
'#blah', " def foo", " end", "end"]
|
88
|
+
expected = {:desc=>"blah", :options=>{:a=>true}, :render_options=>{:b=>1}, :config=>{:a=>true}}
|
89
|
+
CommentInspector.scrape(@lines.join("\n"), 6, Optional).should == expected
|
90
|
+
end
|
91
|
+
|
92
|
+
it "scrapes all comment types with explicit desc" do
|
93
|
+
@lines = ["module Foo", '#@desc blah', '# @render_options :b=>1,', '# :c=>2',
|
94
|
+
' # @options {:a=>true}', ' # @config :a=>true', " def foo", " end", "end"]
|
95
|
+
expected = {:desc=>"blah", :options=>{:a=>true}, :render_options=>{:b=>1, :c=>2}, :config=>{:a=>true}}
|
96
|
+
CommentInspector.scrape(@lines.join("\n"), 7, Optional).should == expected
|
99
97
|
end
|
100
98
|
end
|
data/test/file_library_test.rb
CHANGED
@@ -1,44 +1,42 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
before(:each) { reset; FileLibrary.reset_file_cache }
|
3
|
+
describe "file library" do
|
4
|
+
before { reset; FileLibrary.reset_file_cache }
|
5
|
+
before { Gem.stubs(:loaded_specs).returns({}) } if RUBY_VERSION >= '1.9.2'
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
it "loads" do
|
8
|
+
load :blah, :file_string=>"module Blah; def blah; end; end"
|
9
|
+
library_has_module('blah', 'Boson::Commands::Blah')
|
10
|
+
command_exists?('blah')
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
it "in a subdirectory loads" do
|
14
|
+
load 'site/delicious', :file_string=>"module Delicious; def blah; end; end"
|
15
|
+
library_has_module('site/delicious', "Boson::Commands::Site::Delicious")
|
16
|
+
command_exists?('blah')
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
it "in a sub subdirectory loads" do
|
20
|
+
load 'web/site/delicious', :file_string=>"module Delicious; def blah; end; end"
|
21
|
+
library_has_module('web/site/delicious', "Boson::Commands::Web::Site::Delicious")
|
22
|
+
command_exists?('blah')
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
it "loads by basename" do
|
26
|
+
Dir.stubs(:[]).returns([RUBY_VERSION < '1.9.2' ? './test/commands/site/github.rb' :
|
27
|
+
File.expand_path('./test/commands/site/github.rb')])
|
28
|
+
load 'github', :file_string=>"module Github; def blah; end; end", :exists=>false
|
29
|
+
library_has_module('site/github', "Boson::Commands::Site::Github")
|
30
|
+
command_exists?('blah')
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
it "loads a plugin library by creating its module" do
|
34
|
+
load(:blah, :file_string=>"def blah; end")
|
35
|
+
library_has_module('blah', "Boson::Commands::Blah")
|
36
|
+
command_exists?('blah', false)
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
39
|
+
it "prints error for file library with multiple modules" do
|
40
|
+
capture_stderr { load(:blah, :file_string=>"module Doo; end; module Daa; end") }.should =~ /Can't.*config/
|
43
41
|
end
|
44
42
|
end
|
data/test/loader_test.rb
CHANGED
@@ -1,236 +1,235 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Manager.load([Boson::Commands::Namespace])
|
8
|
-
end
|
9
|
-
|
10
|
-
context "config" do
|
11
|
-
before(:each) { reset }
|
12
|
-
test "from callback overridden by user's config" do
|
13
|
-
with_config(:libraries=>{'blih'=>{:namespace=>false}}) do
|
14
|
-
load :blih, :file_string=>"module Blah; def self.config; {:namespace=>'bling'}; end; end"
|
15
|
-
library('blih').namespace.should == false
|
16
|
-
end
|
17
|
-
end
|
3
|
+
describe "Loader" do
|
4
|
+
def load_namespace_library
|
5
|
+
Manager.load([Boson::Commands::Namespace])
|
6
|
+
end
|
18
7
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
library('blah').command_object('bling').desc.should == 'bling'
|
27
|
-
library('blah').command_object('blang').alias.should == 'ba'
|
28
|
-
end
|
8
|
+
before { Gem.stubs(:loaded_specs).returns({}) } if RUBY_VERSION >= '1.9.2'
|
9
|
+
describe "config" do
|
10
|
+
before { reset }
|
11
|
+
it "from callback overridden by user's config" do
|
12
|
+
with_config(:libraries=>{'blih'=>{:namespace=>false}}) do
|
13
|
+
load :blih, :file_string=>"module Blah; def self.config; {:namespace=>'bling'}; end; end"
|
14
|
+
library('blih').namespace.should == false
|
29
15
|
end
|
16
|
+
end
|
30
17
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
18
|
+
# if this test fails, other exists? using methods fail
|
19
|
+
it "from callback recursively merges with user's config" do
|
20
|
+
with_config(:libraries=>{'blah'=>{:commands=>{'bling'=>{:desc=>'bling', :options=>{:num=>3}}}}}) do
|
21
|
+
File.stubs(:exists?).returns(true)
|
22
|
+
load :blah, :file_string=> "module Blah; def self.config; {:commands=>{'blang'=>{:alias=>'ba'}, " +
|
23
|
+
"'bling'=>{:options=>{:verbose=>:boolean}}}}; end; end"
|
24
|
+
library('blah').command_object('bling').options.should == {:verbose=>:boolean, :num=>3}
|
25
|
+
library('blah').command_object('bling').desc.should == 'bling'
|
26
|
+
library('blah').command_object('blang').alias.should == 'ba'
|
36
27
|
end
|
28
|
+
end
|
37
29
|
|
38
|
-
|
39
|
-
|
40
|
-
|
30
|
+
it "non-hash from inspector overridden by user's config" do
|
31
|
+
with_config(:libraries=>{'blah'=>{:commands=>{'bling'=>{:desc=>'already'}}}}) do
|
32
|
+
load :blah, :file_string=>"module Blah; #from file\ndef bling; end; end"
|
33
|
+
library('blah').command_object('bling').desc.should == 'already'
|
41
34
|
end
|
35
|
+
end
|
42
36
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
load :blah, :file_string=>"module Blah; def blung; end; end"
|
47
|
-
library('blah').command_object('blung').render_options.should == {:fields=>["this"], :sort=>"this"}
|
48
|
-
end
|
49
|
-
end
|
37
|
+
it "from inspector attribute config sets command's config" do
|
38
|
+
load :blah, :file_string=>"module Blah; config :alias=>'ok'\n; def bling; end; end"
|
39
|
+
library('blah').command_object('bling').alias.should == 'ok'
|
50
40
|
end
|
51
41
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
}.should =~ /included blah/
|
42
|
+
it "hash from inspector recursively merged with user's config" do
|
43
|
+
with_config(:libraries=>{'blah'=>{:commands=>{'blung'=>{:args=>[], :render_options=>{:sort=>'this'}}}}}) do
|
44
|
+
CommentInspector.expects(:scrape).returns({:render_options=>{:fields=>['this']}})
|
45
|
+
load :blah, :file_string=>"module Blah; def blung; end; end"
|
46
|
+
library('blah').command_object('blung').render_options.should == {:fields=>["this"], :sort=>"this"}
|
58
47
|
end
|
48
|
+
end
|
49
|
+
end
|
59
50
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
51
|
+
describe "load" do
|
52
|
+
before { reset }
|
53
|
+
it "calls included callback" do
|
54
|
+
capture_stdout {
|
55
|
+
load :blah, :file_string=>"module Blah; def self.included(mod); puts 'included blah'; end; def blah; end; end"
|
56
|
+
}.should =~ /included blah/
|
57
|
+
end
|
65
58
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
59
|
+
it "calls after_included callback" do
|
60
|
+
capture_stdout {
|
61
|
+
load :blah, :file_string=>"module Blah; def self.after_included; puts 'yo'; end; end"
|
62
|
+
}.should == "yo\n"
|
63
|
+
end
|
72
64
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
65
|
+
it "prints error if library module conflicts with top level constant/module" do
|
66
|
+
capture_stderr {
|
67
|
+
load :blah, :file_string=>"module Object; def self.blah; end; end"
|
68
|
+
}.should =~ /conflict.*'Object'/
|
69
|
+
library_loaded?('blah')
|
70
|
+
end
|
78
71
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
72
|
+
it "prints error and returns false for existing library" do
|
73
|
+
libs = create_library('blah', :loaded=>true)
|
74
|
+
Manager.stubs(:loader_create).returns(libs[0])
|
75
|
+
capture_stderr { load('blah', :no_mock=>true, :verbose=>true).should == false }.should =~ /already exists/
|
76
|
+
end
|
86
77
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
78
|
+
it "loads and strips aliases from a library's commands" do
|
79
|
+
with_config(:command_aliases=>{"blah"=>'b'}) do
|
80
|
+
load :blah, :file_string=>"module Blah; def blah; end; alias_method(:b, :blah); end"
|
81
|
+
library_loaded?('blah')
|
82
|
+
library('blah').commands.should == ['blah']
|
93
83
|
end
|
84
|
+
end
|
94
85
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
library_has_module('water', "Boson::Commands::Water")
|
101
|
-
library_has_module('oaks', "Boson::Commands::Oaks")
|
102
|
-
command_exists?('water')
|
103
|
-
command_exists?('oaks')
|
104
|
-
end
|
86
|
+
it "loads a library and creates its class commands" do
|
87
|
+
with_config(:libraries=>{"blah"=>{:class_commands=>{"bling"=>"Blah.bling", "Blah"=>['hmm']}}}) do
|
88
|
+
load :blah, :file_string=>"module Blah; def self.bling; end; def self.hmm; end; end"
|
89
|
+
command_exists? 'bling'
|
90
|
+
command_exists? 'hmm'
|
105
91
|
end
|
92
|
+
end
|
106
93
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
94
|
+
it "loads a library with dependencies" do
|
95
|
+
File.stubs(:exists?).returns(true)
|
96
|
+
File.stubs(:read).returns("module Water; def water; end; end", "module Oaks; def oaks; end; end")
|
97
|
+
with_config(:libraries=>{"water"=>{:dependencies=>"oaks"}}) do
|
98
|
+
load 'water', :no_mock=>true
|
99
|
+
library_has_module('water', "Boson::Commands::Water")
|
100
|
+
library_has_module('oaks', "Boson::Commands::Oaks")
|
101
|
+
command_exists?('water')
|
102
|
+
command_exists?('oaks')
|
116
103
|
end
|
104
|
+
end
|
117
105
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
106
|
+
it "prints error for library with invalid dependencies" do
|
107
|
+
GemLibrary.stubs(:is_a_gem?).returns(true) #mock all as gem libs
|
108
|
+
Util.stubs(:safe_require).returns(true)
|
109
|
+
with_config(:libraries=>{"water"=>{:dependencies=>"fire"}, "fire"=>{:dependencies=>"man"}}) do
|
110
|
+
capture_stderr {
|
111
|
+
load('water', :no_mock=>true)
|
112
|
+
}.should == "Unable to load library fire. Reason: Can't load dependency man\nUnable to load"+
|
113
|
+
" library water. Reason: Can't load dependency fire\n"
|
124
114
|
end
|
115
|
+
end
|
125
116
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
}.should =~ /Unable to load library chwhat.*conflict.*chwhat/
|
132
|
-
end
|
117
|
+
it "prints error for method conflicts with main_object method" do
|
118
|
+
with_config(:error_method_conflicts=>true) do
|
119
|
+
capture_stderr {
|
120
|
+
load('blah', :file_string=>"module Blah; def require; end; end")
|
121
|
+
}.should =~ /Unable to load library blah.*conflict.*require/
|
133
122
|
end
|
123
|
+
end
|
134
124
|
|
135
|
-
|
125
|
+
it "prints error for method conflicts with config error_method_conflicts" do
|
126
|
+
with_config(:error_method_conflicts=>true) do
|
136
127
|
load('blah', :file_string=>"module Blah; def chwhat; end; end")
|
137
128
|
capture_stderr {
|
138
|
-
load('
|
139
|
-
}.should =~ /conflict.*chwhat
|
140
|
-
library_has_command('namespace', 'chwhat2')
|
141
|
-
library_has_command('chwhat2', 'chwhat')
|
129
|
+
load('chwhat', :file_string=>"module Chwhat; def chwhat; end; end")
|
130
|
+
}.should =~ /Unable to load library chwhat.*conflict.*chwhat/
|
142
131
|
end
|
132
|
+
end
|
143
133
|
|
144
|
-
|
145
|
-
|
134
|
+
it "namespaces a library that has a method conflict" do
|
135
|
+
load('blah', :file_string=>"module Blah; def chwhat; end; end")
|
136
|
+
capture_stderr {
|
137
|
+
load('chwhat2', :file_string=>"module Chwhat2; def chwhat; end; end")
|
138
|
+
}.should =~ /conflict.*chwhat.*chwhat2/
|
139
|
+
library_has_command('namespace', 'chwhat2')
|
140
|
+
library_has_command('chwhat2', 'chwhat')
|
141
|
+
end
|
146
142
|
|
147
|
-
|
148
|
-
|
149
|
-
load ::Harvey, :no_mock=>true
|
150
|
-
library_has_command('harvey', 'bird')
|
151
|
-
library_has_command('harvey', 'eagle')
|
152
|
-
end
|
143
|
+
describe "module library" do
|
144
|
+
def mock_library(*args); end
|
153
145
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
146
|
+
it "loads a module library and all its class methods by default" do
|
147
|
+
eval %[module ::Harvey; def self.bird; end; def self.eagle; end; end]
|
148
|
+
load ::Harvey, :no_mock=>true
|
149
|
+
library_has_command('harvey', 'bird')
|
150
|
+
library_has_command('harvey', 'eagle')
|
151
|
+
end
|
160
152
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
end
|
153
|
+
it "loads a module library with specified commands" do
|
154
|
+
eval %[module ::Peanut; def self.bird; end; def self.eagle; end; end]
|
155
|
+
load ::Peanut, :no_mock=>true, :commands=>%w{bird}
|
156
|
+
library('peanut').commands.size.should == 1
|
157
|
+
library_has_command('peanut', 'bird')
|
167
158
|
end
|
168
159
|
|
169
|
-
|
170
|
-
def
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
160
|
+
it "loads a module library as a class" do
|
161
|
+
eval %[class ::Mentok; def self.bird; end; def self.eagle; end; end]
|
162
|
+
load ::Mentok, :no_mock=>true, :commands=>%w{bird}
|
163
|
+
library('mentok').commands.size.should == 1
|
164
|
+
library_has_command('mentok', 'bird')
|
165
|
+
end
|
166
|
+
end
|
176
167
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
168
|
+
describe "gem library" do
|
169
|
+
def mock_library(lib, options={})
|
170
|
+
options[:file_string] ||= ''
|
171
|
+
File.stubs(:exists?).returns(false)
|
172
|
+
GemLibrary.expects(:is_a_gem?).returns(true)
|
173
|
+
Util.expects(:safe_require).with { eval options.delete(:file_string) || ''; true}.returns(true)
|
174
|
+
end
|
184
175
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
command_exists?("
|
176
|
+
it "loads" do
|
177
|
+
with_config(:libraries=>{"dude"=>{:module=>'Dude'}}) do
|
178
|
+
load "dude", :file_string=>"module ::Dude; def blah; end; end"
|
179
|
+
library_has_module('dude', "Dude")
|
180
|
+
command_exists?("blah")
|
190
181
|
end
|
182
|
+
end
|
191
183
|
|
192
|
-
|
193
|
-
|
194
|
-
|
184
|
+
it "with kernel methods loads" do
|
185
|
+
load "dude", :file_string=>"module ::Kernel; def dude; end; end"
|
186
|
+
library_loaded? 'dude'
|
187
|
+
library('dude').module.should == nil
|
188
|
+
command_exists?("dude")
|
189
|
+
end
|
190
|
+
|
191
|
+
it "prints error when nonexistent" do
|
192
|
+
capture_stderr { load('blah') }.should =~ /Unable.*load/
|
193
|
+
end
|
195
194
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
end
|
195
|
+
it "with invalid module prints error" do
|
196
|
+
with_config(:libraries=>{"coolio"=>{:module=>"Cool"}}) do
|
197
|
+
capture_stderr {
|
198
|
+
load('coolio', :file_string=>"module ::Coolio; def coolio; end; end")
|
199
|
+
}.should =~ /Unable.*coolio.*No module/
|
202
200
|
end
|
203
201
|
end
|
204
202
|
end
|
203
|
+
end
|
205
204
|
|
206
|
-
|
207
|
-
|
208
|
-
|
205
|
+
describe "library with namespace" do
|
206
|
+
before_all { reset_main_object }
|
207
|
+
before { reset_boson }
|
209
208
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
end
|
209
|
+
it "loads and defaults to library name" do
|
210
|
+
with_config(:libraries=>{'blang'=>{:namespace=>true}}) do
|
211
|
+
load 'blang', :file_string=>"module Blang; def bling; end; end"
|
212
|
+
library_has_command('blang', 'bling')
|
215
213
|
end
|
214
|
+
end
|
216
215
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
end
|
216
|
+
it "loads with config namespace" do
|
217
|
+
with_config(:libraries=>{'blung'=>{:namespace=>'dope'}}) do
|
218
|
+
load 'blung', :file_string=>"module Blung; def bling; end; end"
|
219
|
+
library_has_command('blung', 'bling')
|
220
|
+
library('blung').commands.size.should == 1
|
223
221
|
end
|
222
|
+
end
|
224
223
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
end
|
224
|
+
it "prints error if namespace conflicts with existing commands" do
|
225
|
+
eval "module ::Conflict; def self.bleng; end; end"
|
226
|
+
load Conflict, :no_mock=>true
|
227
|
+
with_config(:libraries=>{'bleng'=>{:namespace=>true}}) do
|
228
|
+
capture_stderr {
|
229
|
+
load 'bleng', :file_string=>"module Bleng; def bling; end; end"
|
230
|
+
}.should =~ /conflict.*bleng/
|
233
231
|
end
|
234
232
|
end
|
235
233
|
end
|
234
|
+
after_all { FileUtils.rm_r File.dirname(__FILE__)+'/commands/', :force=>true }
|
236
235
|
end
|