bundler_ext 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +50 -52
- data/lib/bundler_ext.rb +36 -1
- data/lib/bundler_ext/gemfile.rb +50 -0
- data/lib/bundler_ext/output.rb +16 -0
- data/lib/bundler_ext/runtime.rb +66 -0
- data/lib/bundler_ext/setup.rb +2 -0
- data/lib/bundler_ext/system.rb +61 -0
- data/lib/bundler_ext/version.rb +1 -1
- data/spec/bundler_ext/bundler_ext_spec.rb +80 -128
- data/spec/bundler_ext/gemfile_spec.rb +191 -0
- data/spec/bundler_ext/integration_spec.rb +146 -0
- data/spec/bundler_ext/runtime_spec.rb +178 -0
- data/spec/bundler_ext/system_spec.rb +138 -0
- data/spec/spec_helper.rb +1 -1
- metadata +21 -8
- data/lib/bundler_ext/bundler_ext.rb +0 -100
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'bundler_ext/gemfile'
|
3
|
+
|
4
|
+
module BundlerExt
|
5
|
+
describe Gemfile do
|
6
|
+
describe "#setup_env" do
|
7
|
+
around(:each) do |spec|
|
8
|
+
orig = ENV['BUNDLE_GEMFILE']
|
9
|
+
spec.run
|
10
|
+
ENV['BUNDLE_GEMFILE'] = orig
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets BUNDLE_GEMFILE env varialbe" do
|
14
|
+
described_class.setup_env('Gemfile.custom')
|
15
|
+
ENV['BUNDLE_GEMFILE'].should == 'Gemfile.custom'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#parse_env" do
|
20
|
+
around(:each) do |spec|
|
21
|
+
beg1 = ENV['BUNDLER_EXT_GROUPS']
|
22
|
+
beg2 = ENV['BEXT_GROUPS']
|
23
|
+
spec.run
|
24
|
+
ENV['BUNDLER_EXT_GROUPS'] = beg1
|
25
|
+
ENV['BEXT_GROUPS'] = beg2
|
26
|
+
end
|
27
|
+
|
28
|
+
it "converts specified groups to symbols" do
|
29
|
+
described_class.parse_env(['development', 'test'])[:groups].should == [:development, :test]
|
30
|
+
end
|
31
|
+
|
32
|
+
it "retrieves extra groups from BUNDLER_EXT_GROUPS env variable" do
|
33
|
+
ENV['BUNDLER_EXT_GROUPS'] = 'development test'
|
34
|
+
env = described_class.parse_env([])
|
35
|
+
env[:groups].should == [:development, :test]
|
36
|
+
env[:extra_groups].should == 'development test'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "retrieves extra groups from BEXT_GROUPS env variable" do
|
40
|
+
ENV['BEXT_GROUPS'] = 'development test'
|
41
|
+
env = described_class.parse_env([])
|
42
|
+
env[:groups].should == [:development, :test]
|
43
|
+
env[:extra_groups].should == 'development test'
|
44
|
+
end
|
45
|
+
|
46
|
+
context "groups == [:all] and no extra groups specified" do
|
47
|
+
it "sets all_groups true" do
|
48
|
+
described_class.parse_env([:all])[:all_groups].should be_true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "groups != [:all]" do
|
53
|
+
it "sets all_groups false" do
|
54
|
+
described_class.parse_env([:dev])[:all_groups].should be_false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "extra groups specified" do
|
59
|
+
it "sets all_groups false" do
|
60
|
+
ENV['BEXT_GROUPS'] = 'development'
|
61
|
+
described_class.parse_env([:all])[:all_groups].should be_false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#dependency_in_env?" do
|
67
|
+
before(:each) do
|
68
|
+
@dep = Bundler::Dependency.new 'rake', '1.0.0', 'group' => [:test]
|
69
|
+
@env = {:groups => []}
|
70
|
+
end
|
71
|
+
|
72
|
+
context "dep.current_platform? is false" do
|
73
|
+
it "returns false" do
|
74
|
+
@env[:all_groups] = true
|
75
|
+
@dep.should_receive(:current_platform?).and_return(false)
|
76
|
+
described_class.dependency_in_env?(@dep, @env).should be_false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context ":all_groups is false and depenency _not_ in env groups" do
|
81
|
+
it "returns false" do
|
82
|
+
@env[:all_groups] = false
|
83
|
+
@env[:groups] << :dev
|
84
|
+
described_class.dependency_in_env?(@dep, @env).should be_false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context ":all_groups and dep.current_platform? are true" do
|
89
|
+
it "returns true" do
|
90
|
+
@env[:all_groups] = true
|
91
|
+
@dep.should_receive(:current_platform?).and_return(true)
|
92
|
+
described_class.dependency_in_env?(@dep, @env).should be_true
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "dep is in a group and dep.current_platform? is true" do
|
97
|
+
it "returns true" do
|
98
|
+
@env[:groups] << :dev
|
99
|
+
@dep.groups << :dev
|
100
|
+
@dep.should_receive(:current_platform?).and_return(true)
|
101
|
+
described_class.dependency_in_env?(@dep, @env).should be_true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#files_for_dependency" do
|
107
|
+
context "dependency in env" do
|
108
|
+
it "returns dependency autorequires" do
|
109
|
+
dep = Bundler::Dependency.new 'rake', '1.0.0', 'require' => [:foo]
|
110
|
+
described_class.should_receive(:dependency_in_env?).and_return(true)
|
111
|
+
described_class.files_for_dependency(dep, {}).should == [:foo]
|
112
|
+
end
|
113
|
+
|
114
|
+
context "autorequires is nil" do
|
115
|
+
it("returns depenency name") do
|
116
|
+
dep = Bundler::Dependency.new 'rake', '1.0.0'
|
117
|
+
described_class.should_receive(:dependency_in_env?).and_return(true)
|
118
|
+
described_class.files_for_dependency(dep, {}).should == ['rake']
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "dependency not in env" do
|
124
|
+
it "returns empty array" do
|
125
|
+
dep = Bundler::Dependency.new 'rake', '1.0.0'
|
126
|
+
described_class.should_receive(:dependency_in_env?).and_return(false)
|
127
|
+
described_class.files_for_dependency(dep, {}).should == []
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#process" do
|
133
|
+
before(:each) do
|
134
|
+
ENV['BUNDLE_GEMFILE'] = 'spec/fixtures/Gemfile.in'
|
135
|
+
@dep = Bundler::Dependency.new 'rake', '1.0.0'
|
136
|
+
@gemfile = Bundler::Dsl.evaluate 'spec/fixtures/Gemfile.in', nil, true
|
137
|
+
@gemfile.should_receive(:dependencies).and_return([@dep])
|
138
|
+
end
|
139
|
+
|
140
|
+
after(:each) do
|
141
|
+
ENV.delete('BUNDLE_GEMFILE')
|
142
|
+
end
|
143
|
+
|
144
|
+
it "returns gemfile dependencies with files" do
|
145
|
+
described_class.should_receive(:files_for_dependency).and_return([:files])
|
146
|
+
described_class.process(@gemfile, {}).should ==
|
147
|
+
{'rake' => {:dep => @dep, :files => [:files]}}
|
148
|
+
end
|
149
|
+
|
150
|
+
it "does not return gemfile dependencies without files" do
|
151
|
+
described_class.should_receive(:files_for_dependency).and_return([])
|
152
|
+
described_class.process(@gemfile, {}).should == {}
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "#parse" do
|
157
|
+
before(:each) do
|
158
|
+
@gemfile = 'spec/fixtures/Gemfile.in'
|
159
|
+
ENV['BUNDLE_GEMFILE'] = @gemfile
|
160
|
+
end
|
161
|
+
|
162
|
+
after(:each) do
|
163
|
+
ENV.delete('BUNDLE_GEMFILE')
|
164
|
+
end
|
165
|
+
|
166
|
+
it "sets up env for gemfile" do
|
167
|
+
described_class.should_receive(:setup_env).with(@gemfile)
|
168
|
+
described_class.parse(@gemfile)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "retrieves env configured by gemfile" do
|
172
|
+
described_class.should_receive(:parse_env).with([:test]).and_call_original
|
173
|
+
described_class.parse(@gemfile, :test)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "evaluates gemfile with bundler dsl" do
|
177
|
+
Bundler::Dsl.should_receive(:evaluate).with(@gemfile, nil, true).and_call_original
|
178
|
+
described_class.parse(@gemfile, :test)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "processes gemfile / returns results" do
|
182
|
+
env = Object.new
|
183
|
+
gemfile = Object.new
|
184
|
+
described_class.should_receive(:parse_env).and_return(env)
|
185
|
+
Bundler::Dsl.should_receive(:evaluate).and_return(gemfile)
|
186
|
+
described_class.should_receive(:process).with(gemfile, env)
|
187
|
+
described_class.parse(@gemfile, :test)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end # describe Gemfile
|
191
|
+
end # module BundlerExt
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# skip system specs unless we can load linux_admin
|
4
|
+
skip_system = false
|
5
|
+
begin
|
6
|
+
require 'linux_admin'
|
7
|
+
rescue LoadError
|
8
|
+
skip_system = true
|
9
|
+
end
|
10
|
+
|
11
|
+
describe BundlerExt do
|
12
|
+
before(:each) do
|
13
|
+
@gemfile = 'spec/fixtures/Gemfile.in'
|
14
|
+
end
|
15
|
+
after(:each) do
|
16
|
+
ENV['BUNDLER_PKG_PREFIX'] = nil
|
17
|
+
ENV['BEXT_ACTIVATE_VERSIONS'] = nil
|
18
|
+
ENV['BEXT_PKG_PREFIX'] = nil
|
19
|
+
ENV['BEXT_NOSTRICT'] = nil
|
20
|
+
ENV['BEXT_GROUPS'] = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#parse_from_gemfile" do
|
24
|
+
describe "with no group passed in" do
|
25
|
+
it "should return nothing to require" do
|
26
|
+
libs = BundlerExt::Gemfile.parse(@gemfile)
|
27
|
+
libs.should be_an(Hash)
|
28
|
+
libs.keys.should_not include('deltacloud-client')
|
29
|
+
libs.keys.should_not include('vcr')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
describe "with :all passed in" do
|
33
|
+
it "should return the list of system libraries in all groups to require" do
|
34
|
+
libs = BundlerExt::Gemfile.parse(@gemfile, :all)
|
35
|
+
libs.should be_an(Hash)
|
36
|
+
libs.keys.should include('deltacloud-client')
|
37
|
+
libs['deltacloud-client'][:files].should == ['deltacloud']
|
38
|
+
libs.keys.should include('vcr')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
describe "with group passed in" do
|
42
|
+
it "should not return any deps that are not in the 'development' group" do
|
43
|
+
libs = BundlerExt::Gemfile.parse(@gemfile,'development')
|
44
|
+
libs.should be_an(Hash)
|
45
|
+
libs.keys.should_not include('deltacloud-client')
|
46
|
+
end
|
47
|
+
it "should return only deps that are in the :test group" do
|
48
|
+
libs = BundlerExt::Gemfile.parse(@gemfile, :test)
|
49
|
+
libs.should be_an(Hash)
|
50
|
+
libs.keys.should_not include('deltacloud-client')
|
51
|
+
libs.keys.should include('vcr')
|
52
|
+
end
|
53
|
+
it "should return deps from both the :default and :test groups" do
|
54
|
+
libs = BundlerExt::Gemfile.parse(@gemfile, :default, :test)
|
55
|
+
libs.should be_an(Hash)
|
56
|
+
libs.keys.should include('deltacloud-client')
|
57
|
+
libs.keys.should include('vcr')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
it "should only return deps for the current platform" do
|
61
|
+
libs = BundlerExt::Gemfile.parse(@gemfile)
|
62
|
+
libs.should be_an(Hash)
|
63
|
+
if RUBY_VERSION < "1.9"
|
64
|
+
libs.keys.should_not include('cinch')
|
65
|
+
else
|
66
|
+
libs.keys.should_not include('fastercsv')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
describe "#system_require" do
|
71
|
+
it "strict mode should fail loading non existing gem" do
|
72
|
+
expect { BundlerExt.system_require(@gemfile, :fail) }.to raise_error
|
73
|
+
end
|
74
|
+
|
75
|
+
it "non-strict mode should load the libraries in the gemfile" do
|
76
|
+
ENV['BEXT_NOSTRICT'] = 'true'
|
77
|
+
BundlerExt.system_require(@gemfile)
|
78
|
+
defined?(Gem).should be_true
|
79
|
+
end
|
80
|
+
|
81
|
+
it "non-strict mode should load the libraries in the gemfile" do
|
82
|
+
ENV['BUNDLER_EXT_NOSTRICT'] = 'true'
|
83
|
+
BundlerExt.system_require(@gemfile)
|
84
|
+
defined?(Gem).should be_true
|
85
|
+
end
|
86
|
+
|
87
|
+
it "non-strict mode should load the libraries in the gemfile" do
|
88
|
+
ENV['BEXT_NOSTRICT'] = 'true'
|
89
|
+
BundlerExt.system_require(@gemfile, :fail)
|
90
|
+
defined?(Gem).should be_true
|
91
|
+
end
|
92
|
+
|
93
|
+
it "non-strict mode should load the libraries in the gemfile" do
|
94
|
+
ENV['BUNDLER_EXT_NOSTRICT'] = 'true'
|
95
|
+
BundlerExt.system_require(@gemfile, :fail)
|
96
|
+
defined?(Gem).should be_true
|
97
|
+
end
|
98
|
+
it "non-strict mode should load the libraries using env var list" do
|
99
|
+
ENV['BEXT_GROUPS'] = 'test development blah'
|
100
|
+
ENV['BEXT_NOSTRICT'] = 'true'
|
101
|
+
BundlerExt.system_require(@gemfile)
|
102
|
+
defined?(Gem::Command).should be_true
|
103
|
+
end
|
104
|
+
|
105
|
+
it "non-strict mode should load the libraries using env var list" do
|
106
|
+
ENV['BUNLDER_EXT_GROUPS'] = 'test development blah'
|
107
|
+
ENV['BEXT_NOSTRICT'] = 'true'
|
108
|
+
BundlerExt.system_require(@gemfile)
|
109
|
+
defined?(Gem::Command).should be_true
|
110
|
+
end
|
111
|
+
|
112
|
+
unless skip_system
|
113
|
+
context "ENV['BEXT_ACTIVATE_VERSIONS'] is true" do
|
114
|
+
before(:each) do
|
115
|
+
ENV['BUNDLER_EXT_NOSTRICT'] = 'true'
|
116
|
+
ENV['BEXT_ACTIVATE_VERSIONS'] = 'true'
|
117
|
+
end
|
118
|
+
|
119
|
+
it "activates the version of the system installed package" do
|
120
|
+
gems = BundlerExt::Gemfile.parse(@gemfile, :all)
|
121
|
+
gems.each { |gem,gdep|
|
122
|
+
version = rand(100)
|
123
|
+
BundlerExt::System.should_receive(:system_name_for).with(gem).
|
124
|
+
and_return(gem)
|
125
|
+
BundlerExt::System.should_receive(:system_version_for).with(gem).
|
126
|
+
and_return(version)
|
127
|
+
BundlerExt::System.should_receive(:gem).with(gem, "=#{version}")
|
128
|
+
}
|
129
|
+
BundlerExt.system_require(@gemfile, :all)
|
130
|
+
end
|
131
|
+
|
132
|
+
context "ENV['BEXT_PKG_PREFIX'] is specified" do
|
133
|
+
it "prepends bundler pkg prefix onto system package name to load" do
|
134
|
+
ENV['BEXT_PKG_PREFIX'] = 'rubygem-'
|
135
|
+
gems = BundlerExt::Gemfile.parse(@gemfile, :all)
|
136
|
+
gems.each { |gem,gdep|
|
137
|
+
BundlerExt::System.should_receive(:system_version_for).with("rubygem-#{gem}").
|
138
|
+
and_return('0')
|
139
|
+
}
|
140
|
+
BundlerExt.system_require(@gemfile, :all)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'bundler_ext/runtime'
|
3
|
+
|
4
|
+
module BundlerExt
|
5
|
+
describe Runtime do
|
6
|
+
describe "#gemfile" do
|
7
|
+
it "gets/sets bext_gemfile" do
|
8
|
+
runtime = described_class.new
|
9
|
+
runtime.gemfile('Gemfile.in').should == 'Gemfile.in'
|
10
|
+
runtime.gemfile.should == 'Gemfile.in'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "defaults to Bundler.default_gemfile" do
|
14
|
+
Bundler.should_receive(:default_gemfile).and_return('DefaultGemfile')
|
15
|
+
runtime = described_class.new
|
16
|
+
runtime.gemfile.should == 'DefaultGemfile'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#root" do
|
21
|
+
it "returns directory name of gemfile" do
|
22
|
+
runtime = described_class.new
|
23
|
+
runtime.gemfile(Pathname.new('spec/fixtures/Gemfile.in'))
|
24
|
+
runtime.root.to_s.should == File.expand_path('spec/fixtures')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#bundler" do
|
29
|
+
it "returns handle to bundler runtime" do
|
30
|
+
runtime = described_class.new
|
31
|
+
runtime.gemfile(Pathname.new('spec/fixtures/Gemfile.in'))
|
32
|
+
bundler = runtime.bundler
|
33
|
+
bundler.should be_an_instance_of(Bundler::Runtime)
|
34
|
+
bundler.root.to_s.should == File.expand_path('spec/fixtures')
|
35
|
+
runtime.bundler.should == bundler
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#rubygems" do
|
40
|
+
it "returns handle to bundler rubygems integration" do
|
41
|
+
runtime = described_class.new
|
42
|
+
rubygems = runtime.rubygems
|
43
|
+
rubygems.should be_an_instance_of(Bundler::RubygemsIntegration)
|
44
|
+
runtime.rubygems.should == rubygems
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#setup_env" do
|
49
|
+
around(:each) do |spec|
|
50
|
+
orig = ENV
|
51
|
+
spec.run
|
52
|
+
ENV = orig
|
53
|
+
end
|
54
|
+
|
55
|
+
it "assigns env home variable to BEXT_HOME" do
|
56
|
+
ENV['BEXT_HOME'] = '/home/foo'
|
57
|
+
described_class.new.setup_env
|
58
|
+
ENV['HOME'].should == '/home/foo'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "assigns env home variable to BUNDLER_EXT_HOME" do
|
62
|
+
ENV['BUNDLER_EXT_HOME'] = '/home/foo'
|
63
|
+
described_class.new.setup_env
|
64
|
+
ENV['HOME'].should == '/home/foo'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "::namespaced_file" do
|
69
|
+
context "file does not include '-'" do
|
70
|
+
it "returns nil" do
|
71
|
+
described_class.namespaced_file('foobar').should be_nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "file responds to :name" do
|
76
|
+
it "returns file name in path format" do
|
77
|
+
file = Pathname.new 'foo-bar'
|
78
|
+
file.should_receive(:name).and_return('foo-bar')
|
79
|
+
described_class.namespaced_file(file).should == 'foo/bar'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns file in path format" do
|
84
|
+
described_class.namespaced_file("foo-bar").should == 'foo/bar'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#system_require" do
|
89
|
+
it "requires files" do
|
90
|
+
runtime = described_class.new
|
91
|
+
runtime.should_receive(:require).with('file1')
|
92
|
+
runtime.system_require(['file1'])
|
93
|
+
end
|
94
|
+
|
95
|
+
context "LoadError when requiring file" do
|
96
|
+
it "requires namespaced file" do
|
97
|
+
described_class.should_receive(:namespaced_file).with('file1').
|
98
|
+
and_return('namespaced_file1')
|
99
|
+
runtime = described_class.new
|
100
|
+
runtime.should_receive(:require).with('file1').and_call_original
|
101
|
+
runtime.should_receive(:require).with('namespaced_file1')
|
102
|
+
runtime.system_require(['file1'])
|
103
|
+
end
|
104
|
+
|
105
|
+
context "LoadError when requiring namespaced file" do
|
106
|
+
it "outputs strict error" do
|
107
|
+
expected = 'Gem loading error: cannot load such file -- namespaced_file1'
|
108
|
+
Output.should_receive(:strict_err).with(expected)
|
109
|
+
|
110
|
+
described_class.should_receive(:namespaced_file).with('file1').
|
111
|
+
and_return('namespaced_file1')
|
112
|
+
runtime = described_class.new
|
113
|
+
runtime.should_receive(:require).with('file1').and_call_original
|
114
|
+
runtime.should_receive(:require).with('namespaced_file1').and_call_original
|
115
|
+
runtime.system_require(['file1'])
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "namespaced file is nil" do
|
120
|
+
it "outputs strict error" do
|
121
|
+
expected = 'Gem loading error: cannot load such file -- file1'
|
122
|
+
Output.should_receive(:strict_err).with(expected)
|
123
|
+
|
124
|
+
described_class.should_receive(:namespaced_file).with('file1').
|
125
|
+
and_return(nil)
|
126
|
+
runtime = described_class.new
|
127
|
+
runtime.should_receive(:require).with('file1').and_call_original
|
128
|
+
runtime.system_require(['file1'])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "clear" do
|
135
|
+
it "cleans bundler load path" do
|
136
|
+
runtime = described_class.new
|
137
|
+
runtime.bundler.should_receive(:clean_load_path)
|
138
|
+
runtime.clear
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "add_spec" do
|
143
|
+
around(:each) do |spec|
|
144
|
+
orig = $LOAD_PATH
|
145
|
+
spec.run
|
146
|
+
|
147
|
+
# XXX need to restore this way else we'll get an err:
|
148
|
+
# "$LOAD_PATH is a read-only variable"
|
149
|
+
$LOAD_PATH.clear
|
150
|
+
orig.each { |o| $LOAD_PATH << o }
|
151
|
+
end
|
152
|
+
|
153
|
+
it "marks spec as loaded" do
|
154
|
+
spec = Gem::Specification.new
|
155
|
+
runtime = described_class.new
|
156
|
+
runtime.rubygems.should_receive(:mark_loaded).with(spec)
|
157
|
+
runtime.add_spec(spec)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "adds spec load paths not already on LOAD_PATH to it" do
|
161
|
+
$LOAD_PATH.clear
|
162
|
+
spec = Gem::Specification.new :load_paths => ['foo']
|
163
|
+
runtime = described_class.new
|
164
|
+
runtime.add_spec(spec)
|
165
|
+
$LOAD_PATH.should include(*spec.load_paths)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "skips paths already on the $LOAD_PATH" do
|
169
|
+
spec = Gem::Specification.new :load_paths => ['foo']
|
170
|
+
$LOAD_PATH.clear
|
171
|
+
$LOAD_PATH << spec.load_paths.first
|
172
|
+
runtime = described_class.new
|
173
|
+
runtime.add_spec(spec)
|
174
|
+
$LOAD_PATH.size.should == 1
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end # describe Runtime
|
178
|
+
end # module BundlerExt
|