boson 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,100 +1,98 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- module Boson
4
- class ScraperTest < Test::Unit::TestCase
5
- before(:all) { eval "module Optional; def self.bling; {:a=>'bling'}; end; end" }
6
- context "description" do
7
- before(:each) {
8
- @lines = ["module Foo", " # some comments yay", " def foo", " end", "end"]
9
- }
10
- def description(options={})
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
- context "options" do
46
- before(:each) {
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
- test "scrape all comment types with implicit desc" do
87
- @lines = ["module Foo", '# @config :a=>true', '# @render_options :b=>1', ' # @options {:a=>true}',
88
- '#blah', " def foo", " end", "end"]
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
- test "scrape all comment types with explicit desc" do
94
- @lines = ["module Foo", '#@desc blah', '# @render_options :b=>1,', '# :c=>2',
95
- ' # @options {:a=>true}', ' # @config :a=>true', " def foo", " end", "end"]
96
- expected = {:desc=>"blah", :options=>{:a=>true}, :render_options=>{:b=>1, :c=>2}, :config=>{:a=>true}}
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
@@ -1,44 +1,42 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- module Boson
4
- class FileLibraryTest < Test::Unit::TestCase
5
- context "file library" do
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
- test "loads" do
9
- load :blah, :file_string=>"module Blah; def blah; end; end"
10
- library_has_module('blah', 'Boson::Commands::Blah')
11
- command_exists?('blah')
12
- end
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
- test "in a subdirectory loads" do
15
- load 'site/delicious', :file_string=>"module Delicious; def blah; end; end"
16
- library_has_module('site/delicious', "Boson::Commands::Site::Delicious")
17
- command_exists?('blah')
18
- end
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
- test "in a sub subdirectory loads" do
21
- load 'web/site/delicious', :file_string=>"module Delicious; def blah; end; end"
22
- library_has_module('web/site/delicious', "Boson::Commands::Web::Site::Delicious")
23
- command_exists?('blah')
24
- end
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
- test "loads by basename" do
27
- Dir.stubs(:[]).returns(['./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
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
- test "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
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
- test "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/
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
- module Boson
4
- class LoaderTest < Test::Unit::TestCase
5
-
6
- def load_namespace_library
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
- # if this test fails, other exists? using methods fail
20
- test "from callback recursively merges with user's config" do
21
- with_config(:libraries=>{'blah'=>{:commands=>{'bling'=>{:desc=>'bling', :options=>{:num=>3}}}}}) do
22
- File.stubs(:exists?).returns(true)
23
- load :blah, :file_string=> "module Blah; def self.config; {:commands=>{'blang'=>{:alias=>'ba'}, " +
24
- "'bling'=>{:options=>{:verbose=>:boolean}}}}; end; end"
25
- library('blah').command_object('bling').options.should == {:verbose=>:boolean, :num=>3}
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
- test "non-hash from inspector overridden by user's config" do
32
- with_config(:libraries=>{'blah'=>{:commands=>{'bling'=>{:desc=>'already'}}}}) do
33
- load :blah, :file_string=>"module Blah; #from file\ndef bling; end; end"
34
- library('blah').command_object('bling').desc.should == 'already'
35
- end
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
- test "from inspector attribute config sets command's config" do
39
- load :blah, :file_string=>"module Blah; config :alias=>'ok'\n; def bling; end; end"
40
- library('blah').command_object('bling').alias.should == 'ok'
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
- test "hash from inspector recursively merged with user's config" do
44
- with_config(:libraries=>{'blah'=>{:commands=>{'blung'=>{:args=>[], :render_options=>{:sort=>'this'}}}}}) do
45
- CommentInspector.expects(:scrape).returns({:render_options=>{:fields=>['this']}})
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
- context "load" do
53
- before(:each) { reset }
54
- test "calls included callback" do
55
- capture_stdout {
56
- load :blah, :file_string=>"module Blah; def self.included(mod); puts 'included blah'; end; def blah; end; end"
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
- test "calls after_included callback" do
61
- capture_stdout {
62
- load :blah, :file_string=>"module Blah; def self.after_included; puts 'yo'; end; end"
63
- }.should == "yo\n"
64
- end
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
- test "prints error if library module conflicts with top level constant/module" do
67
- capture_stderr {
68
- load :blah, :file_string=>"module Object; def self.blah; end; end"
69
- }.should =~ /conflict.*'Object'/
70
- library_loaded?('blah')
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
- test "prints error and returns false for existing library" do
74
- libs = create_library('blah', :loaded=>true)
75
- Manager.stubs(:loader_create).returns(libs[0])
76
- capture_stderr { load('blah', :no_mock=>true, :verbose=>true).should == false }.should =~ /already exists/
77
- end
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
- test "loads and strips aliases from a library's commands" do
80
- with_config(:command_aliases=>{"blah"=>'b'}) do
81
- load :blah, :file_string=>"module Blah; def blah; end; alias_method(:b, :blah); end"
82
- library_loaded?('blah')
83
- library('blah').commands.should == ['blah']
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
- test "loads a library and creates its class commands" do
88
- with_config(:libraries=>{"blah"=>{:class_commands=>{"bling"=>"Blah.bling", "Blah"=>['hmm']}}}) do
89
- load :blah, :file_string=>"module Blah; def self.bling; end; def self.hmm; end; end"
90
- command_exists? 'bling'
91
- command_exists? 'hmm'
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
- test "loads a library with dependencies" do
96
- File.stubs(:exists?).returns(true)
97
- File.stubs(:read).returns("module Water; def water; end; end", "module Oaks; def oaks; end; end")
98
- with_config(:libraries=>{"water"=>{:dependencies=>"oaks"}}) do
99
- load 'water', :no_mock=>true
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
- test "prints error for library with invalid dependencies" do
108
- GemLibrary.stubs(:is_a_gem?).returns(true) #mock all as gem libs
109
- Util.stubs(:safe_require).returns(true)
110
- with_config(:libraries=>{"water"=>{:dependencies=>"fire"}, "fire"=>{:dependencies=>"man"}}) do
111
- capture_stderr {
112
- load('water', :no_mock=>true)
113
- }.should == "Unable to load library fire. Reason: Can't load dependency man\nUnable to load"+
114
- " library water. Reason: Can't load dependency fire\n"
115
- end
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
- test "prints error for method conflicts with main_object method" do
119
- with_config(:error_method_conflicts=>true) do
120
- capture_stderr {
121
- load('blah', :file_string=>"module Blah; def require; end; end")
122
- }.should =~ /Unable to load library blah.*conflict.*require/
123
- end
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
- test "prints error for method conflicts with config error_method_conflicts" do
127
- with_config(:error_method_conflicts=>true) do
128
- load('blah', :file_string=>"module Blah; def chwhat; end; end")
129
- capture_stderr {
130
- load('chwhat', :file_string=>"module Chwhat; def chwhat; end; end")
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
- test "namespaces a library that has a method conflict" do
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('chwhat2', :file_string=>"module Chwhat2; def chwhat; end; end")
139
- }.should =~ /conflict.*chwhat.*chwhat2/
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
- context "module library" do
145
- def mock_library(*args); end
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
- test "loads a module library and all its class methods by default" do
148
- eval %[module ::Harvey; def self.bird; end; def self.eagle; end; end]
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
- test "loads a module library with specified commands" do
155
- eval %[module ::Peanut; def self.bird; end; def self.eagle; end; end]
156
- load ::Peanut, :no_mock=>true, :commands=>%w{bird}
157
- library('peanut').commands.size.should == 1
158
- library_has_command('peanut', 'bird')
159
- end
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
- test "loads a module library as a class" do
162
- eval %[class ::Mentok; def self.bird; end; def self.eagle; end; end]
163
- load ::Mentok, :no_mock=>true, :commands=>%w{bird}
164
- library('mentok').commands.size.should == 1
165
- library_has_command('mentok', 'bird')
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
- context "gem library" do
170
- def mock_library(lib, options={})
171
- options[:file_string] ||= ''
172
- File.stubs(:exists?).returns(false)
173
- GemLibrary.expects(:is_a_gem?).returns(true)
174
- Util.expects(:safe_require).with { eval options.delete(:file_string) || ''; true}.returns(true)
175
- end
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
- test "loads" do
178
- with_config(:libraries=>{"dude"=>{:module=>'Dude'}}) do
179
- load "dude", :file_string=>"module ::Dude; def blah; end; end"
180
- library_has_module('dude', "Dude")
181
- command_exists?("blah")
182
- end
183
- end
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
- test "with kernel methods loads" do
186
- load "dude", :file_string=>"module ::Kernel; def dude; end; end"
187
- library_loaded? 'dude'
188
- library('dude').module.should == nil
189
- command_exists?("dude")
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
- test "prints error when nonexistent" do
193
- capture_stderr { load('blah') }.should =~ /Unable.*load/
194
- end
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
- test "with invalid module prints error" do
197
- with_config(:libraries=>{"coolio"=>{:module=>"Cool"}}) do
198
- capture_stderr {
199
- load('coolio', :file_string=>"module ::Coolio; def coolio; end; end")
200
- }.should =~ /Unable.*coolio.*No module/
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
- context "library with namespace" do
207
- before(:all) { reset_main_object }
208
- before(:each) { reset_boson }
205
+ describe "library with namespace" do
206
+ before_all { reset_main_object }
207
+ before { reset_boson }
209
208
 
210
- test "loads and defaults to library name" do
211
- with_config(:libraries=>{'blang'=>{:namespace=>true}}) do
212
- load 'blang', :file_string=>"module Blang; def bling; end; end"
213
- library_has_command('blang', 'bling')
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
- test "loads with config namespace" do
218
- with_config(:libraries=>{'blung'=>{:namespace=>'dope'}}) do
219
- load 'blung', :file_string=>"module Blung; def bling; end; end"
220
- library_has_command('blung', 'bling')
221
- library('blung').commands.size.should == 1
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
- test "prints error if namespace conflicts with existing commands" do
226
- eval "module Conflict; def self.bleng; end; end"
227
- load Conflict, :no_mock=>true
228
- with_config(:libraries=>{'bleng'=>{:namespace=>true}}) do
229
- capture_stderr {
230
- load 'bleng', :file_string=>"module Bleng; def bling; end; end"
231
- }.should =~ /conflict.*bleng/
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