isolate 1.10.2 → 2.0.0.pre.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/CHANGELOG.rdoc +28 -0
- data/Manifest.txt +8 -0
- data/README.rdoc +29 -39
- data/Rakefile +3 -0
- data/lib/hoe/isolate.rb +3 -3
- data/lib/isolate.rb +20 -261
- data/lib/isolate/entry.rb +107 -0
- data/lib/isolate/now.rb +2 -0
- data/lib/isolate/rake.rb +35 -10
- data/lib/isolate/sandbox.rb +256 -0
- data/test/fixtures/blort-0.0.gem +0 -0
- data/test/fixtures/override.rb +1 -0
- data/test/fixtures/override.rb.local +3 -0
- data/test/isolate/test.rb +53 -0
- data/test/test_isolate.rb +11 -241
- data/test/test_isolate_entry.rb +86 -0
- data/test/test_isolate_sandbox.rb +275 -0
- metadata +28 -12
data/test/test_isolate.rb
CHANGED
@@ -1,25 +1,13 @@
|
|
1
|
-
require "
|
2
|
-
|
3
|
-
require "rubygems/requirement"
|
1
|
+
require "isolate/test"
|
2
|
+
|
4
3
|
require "isolate"
|
5
4
|
|
6
|
-
class TestIsolate <
|
5
|
+
class TestIsolate < Isolate::Test
|
7
6
|
WITH_HOE = "test/fixtures/with-hoe"
|
8
7
|
|
9
|
-
def setup
|
10
|
-
@isolate = Isolate.new "tmp/gems", :install => false, :verbose => false
|
11
|
-
@env = ENV.to_hash
|
12
|
-
|
13
|
-
Gem.loaded_specs.clear
|
14
|
-
end
|
15
|
-
|
16
8
|
def teardown
|
17
|
-
|
18
|
-
|
19
|
-
Gem::DependencyInstaller.reset_value
|
20
|
-
Gem::Uninstaller.reset_value
|
21
|
-
FileUtils.rm_rf "tmp/gems"
|
22
|
-
ENV.replace @env
|
9
|
+
Isolate.sandbox.disable if Isolate.sandbox
|
10
|
+
super
|
23
11
|
end
|
24
12
|
|
25
13
|
def test_self_env
|
@@ -40,233 +28,15 @@ class TestIsolate < MiniTest::Unit::TestCase
|
|
40
28
|
assert_equal "baz", Isolate.env
|
41
29
|
end
|
42
30
|
|
43
|
-
def
|
44
|
-
assert_nil Isolate.
|
31
|
+
def test_self_now!
|
32
|
+
assert_nil Isolate.sandbox
|
45
33
|
|
46
|
-
Isolate.
|
34
|
+
Isolate.now! :path => WITH_HOE, :multiruby => false, :system => false do
|
47
35
|
gem "hoe"
|
48
36
|
end
|
49
37
|
|
50
|
-
refute_nil Isolate.
|
51
|
-
assert_equal File.expand_path(WITH_HOE), Isolate.
|
52
|
-
assert_equal "hoe", Isolate.
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_activate
|
56
|
-
@isolate = Isolate.new WITH_HOE
|
57
|
-
|
58
|
-
assert_nil Gem.loaded_specs["hoe"]
|
59
|
-
|
60
|
-
@isolate.gem "hoe"
|
61
|
-
@isolate.activate
|
62
|
-
|
63
|
-
refute_nil Gem.loaded_specs["hoe"]
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_activate_environment
|
67
|
-
@isolate = Isolate.new WITH_HOE, :verbose => false
|
68
|
-
@isolate.gem "rubyforge"
|
69
|
-
|
70
|
-
@isolate.environment "borg" do
|
71
|
-
gem "hoe"
|
72
|
-
end
|
73
|
-
|
74
|
-
@isolate.activate
|
75
|
-
assert_nil Gem.loaded_specs["hoe"]
|
76
|
-
refute_nil Gem.loaded_specs["rubyforge"]
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_activate_environment_explicit
|
80
|
-
@isolate = Isolate.new WITH_HOE
|
81
|
-
|
82
|
-
@isolate.gem "rubyforge"
|
83
|
-
|
84
|
-
@isolate.environment "borg" do
|
85
|
-
gem "hoe"
|
86
|
-
end
|
87
|
-
|
88
|
-
@isolate.activate "borg"
|
89
|
-
refute_nil Gem.loaded_specs["hoe"]
|
90
|
-
refute_nil Gem.loaded_specs["rubyforge"]
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_activate_install
|
94
|
-
@isolate = Isolate.new "tmp/gems", :install => true, :verbose => false
|
95
|
-
|
96
|
-
@isolate.gem "foo"
|
97
|
-
|
98
|
-
# rescuing because activate, well, actually tries to activate
|
99
|
-
begin; @isolate.activate; rescue Gem::LoadError; end
|
100
|
-
|
101
|
-
assert_equal ["foo", Gem::Requirement.default],
|
102
|
-
Gem::DependencyInstaller.value.shift
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_activate_install_environment
|
106
|
-
@isolate = Isolate.new "tmp/gems", :install => true
|
107
|
-
@isolate.environment(:nope) { gem "foo" }
|
108
|
-
|
109
|
-
@isolate.activate
|
110
|
-
assert_empty Gem::DependencyInstaller.value
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_activate_ret
|
114
|
-
assert_equal @isolate, @isolate.activate
|
115
|
-
end
|
116
|
-
|
117
|
-
# TODO: cleanup with 2 versions of same gem, 1 activated
|
118
|
-
# TODO: install with 1 older version, 1 new gem to be installed
|
119
|
-
|
120
|
-
def test_cleanup
|
121
|
-
@isolate = Isolate.new WITH_HOE, :verbose => false
|
122
|
-
# no gems specified on purpose
|
123
|
-
@isolate.activate
|
124
|
-
|
125
|
-
expected = [["hoe", "2.3.3", WITH_HOE],
|
126
|
-
["rake", "0.8.7", WITH_HOE],
|
127
|
-
["rubyforge", "1.0.4", WITH_HOE]]
|
128
|
-
|
129
|
-
assert_equal expected, Gem::Uninstaller.value
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_disable
|
133
|
-
home, path, bin = ENV.values_at "GEM_HOME", "GEM_PATH", "PATH"
|
134
|
-
load_path = $LOAD_PATH.dup
|
135
|
-
|
136
|
-
@isolate.enable
|
137
|
-
|
138
|
-
refute_equal home, ENV["GEM_HOME"]
|
139
|
-
refute_equal path, ENV["GEM_PATH"]
|
140
|
-
refute_equal bin, ENV["PATH"]
|
141
|
-
|
142
|
-
refute_equal load_path, $LOAD_PATH
|
143
|
-
|
144
|
-
@isolate.disable
|
145
|
-
|
146
|
-
assert_equal home, ENV["GEM_HOME"]
|
147
|
-
assert_equal path, ENV["GEM_PATH"]
|
148
|
-
assert_equal bin, ENV["PATH"]
|
149
|
-
assert_equal load_path, $LOAD_PATH
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_disable_ret
|
153
|
-
assert_equal @isolate, @isolate.disable
|
154
|
-
end
|
155
|
-
|
156
|
-
def test_enable
|
157
|
-
refute_empty Gem.find_files("minitest/unit.rb"),
|
158
|
-
"There's a minitest/unit in the current env, since we're running it."
|
159
|
-
|
160
|
-
@isolate.enable
|
161
|
-
|
162
|
-
assert_equal @isolate.path, ENV["GEM_PATH"]
|
163
|
-
assert_equal @isolate.path, ENV["GEM_HOME"]
|
164
|
-
assert ENV["PATH"].include?(File.join(@isolate.path, "bin")), "in path"
|
165
|
-
|
166
|
-
assert_equal [], Gem.find_files("minitest/unit.rb"),
|
167
|
-
"Can't find minitest/unit now, 'cause we're activated!"
|
168
|
-
|
169
|
-
assert_empty Gem.loaded_specs
|
170
|
-
assert_equal [@isolate.path], Gem.path
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_enable_ret
|
174
|
-
assert_equal @isolate, @isolate.enable
|
175
|
-
end
|
176
|
-
|
177
|
-
def test_environment
|
178
|
-
@isolate.gem "none"
|
179
|
-
|
180
|
-
@isolate.environment "test", "ci" do
|
181
|
-
gem "test-ci"
|
182
|
-
|
183
|
-
environment "production" do
|
184
|
-
gem "test-ci-production"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
none, test_ci, test_ci_production = @isolate.entries
|
189
|
-
|
190
|
-
assert_equal [], none.environments
|
191
|
-
assert_equal %w(test ci), test_ci.environments
|
192
|
-
assert_equal %w(test ci production), test_ci_production.environments
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_gem
|
196
|
-
g = @isolate.gem "foo"
|
197
|
-
assert_includes @isolate.entries, g
|
198
|
-
|
199
|
-
assert_equal "foo", g.name
|
200
|
-
assert_equal Gem::Requirement.create(">= 0"), g.requirement
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_gem_multi_requirements
|
204
|
-
g = @isolate.gem "foo", "= 1.0", "< 2.0"
|
205
|
-
assert_equal Gem::Requirement.create(["= 1.0", "< 2.0"]), g.requirement
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_gem_options
|
209
|
-
g = @isolate.gem "foo", :source => "somewhere"
|
210
|
-
assert_equal "somewhere", g.options[:source]
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_initialize
|
214
|
-
i = Isolate.new "foo/gems"
|
215
|
-
assert_equal File.expand_path("foo/gems"), i.path
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_initialize_block
|
219
|
-
i = Isolate.new "foo/gems" do
|
220
|
-
gem "hoe"
|
221
|
-
end
|
222
|
-
|
223
|
-
assert_equal "hoe", i.entries.first.name
|
224
|
-
end
|
225
|
-
|
226
|
-
def test_initialize_options
|
227
|
-
i = Isolate.new "foo/gems"
|
228
|
-
assert i.install?
|
229
|
-
assert i.verbose?
|
230
|
-
assert i.cleanup?
|
231
|
-
|
232
|
-
i = Isolate.new "foo/gems",
|
233
|
-
:cleanup => false, :install => false, :verbose => false
|
234
|
-
|
235
|
-
refute i.cleanup?
|
236
|
-
refute i.install?
|
237
|
-
refute i.verbose?
|
238
|
-
|
239
|
-
i = Isolate.new "foo/gems", :install => false
|
240
|
-
refute i.cleanup?, "no install, no cleanup"
|
241
|
-
|
242
|
-
i = Isolate.new "foo/gems", :file => "test/fixtures/isolate.rb"
|
243
|
-
assert_equal "hoe", i.entries.first.name
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
module BrutalStub
|
248
|
-
@@value = []
|
249
|
-
def value; @@value end
|
250
|
-
def reset_value; value.clear end
|
251
|
-
end
|
252
|
-
|
253
|
-
class Gem::DependencyInstaller
|
254
|
-
extend BrutalStub
|
255
|
-
|
256
|
-
alias old_install install
|
257
|
-
def install name, requirement
|
258
|
-
self.class.value << [name, requirement]
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
class Gem::Uninstaller
|
263
|
-
extend BrutalStub
|
264
|
-
|
265
|
-
attr_reader :gem, :version, :gem_home
|
266
|
-
alias old_uninstall uninstall
|
267
|
-
def uninstall
|
268
|
-
self.class.value << [self.gem,
|
269
|
-
self.version.to_s,
|
270
|
-
self.gem_home.sub(Dir.pwd + "/", '')]
|
38
|
+
refute_nil Isolate.sandbox
|
39
|
+
assert_equal File.expand_path(WITH_HOE), Isolate.sandbox.path
|
40
|
+
assert_equal "hoe", Isolate.sandbox.entries.first.name
|
271
41
|
end
|
272
42
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "isolate/entry"
|
2
|
+
require "isolate/test"
|
3
|
+
|
4
|
+
class TestIsolateEntry < Isolate::Test
|
5
|
+
def setup
|
6
|
+
@sandbox = Object.new
|
7
|
+
def @sandbox.environments; @e ||= [] end
|
8
|
+
def @sandbox.path; "tmp/gems" end
|
9
|
+
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialize
|
14
|
+
@sandbox.environments.concat %w(foo bar)
|
15
|
+
|
16
|
+
entry = e "baz", "> 1.0", "< 2.0", :quux => :corge
|
17
|
+
|
18
|
+
assert_equal %w(foo bar), entry.environments
|
19
|
+
assert_equal "baz", entry.name
|
20
|
+
assert_equal Gem::Requirement.new("> 1.0", "< 2.0"), entry.requirement
|
21
|
+
assert_equal :corge, entry.options[:quux]
|
22
|
+
|
23
|
+
entry = e "plugh"
|
24
|
+
|
25
|
+
assert_equal Gem::Requirement.default, entry.requirement
|
26
|
+
assert_equal({}, entry.options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_install_file
|
30
|
+
file = "test/fixtures/blort-0.0.gem"
|
31
|
+
entry = e file
|
32
|
+
entry.install
|
33
|
+
|
34
|
+
assert_equal File.expand_path(file),
|
35
|
+
Gem::DependencyInstaller.value.first.first
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_matches?
|
39
|
+
@sandbox.environments << "test"
|
40
|
+
entry = e "hi"
|
41
|
+
|
42
|
+
assert entry.matches?("test")
|
43
|
+
assert !entry.matches?("double secret production")
|
44
|
+
|
45
|
+
entry.environments.clear
|
46
|
+
assert entry.matches?("double secret production")
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_matches_spec?
|
50
|
+
entry = e "hi", "1.1"
|
51
|
+
|
52
|
+
assert entry.matches_spec?(spec "hi", "1.1")
|
53
|
+
assert !entry.matches_spec?(spec "bye", "1.1")
|
54
|
+
assert !entry.matches_spec?(spec "hi", "1.2")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_update
|
58
|
+
entry = e "hi", "1.1"
|
59
|
+
|
60
|
+
assert_equal [], entry.environments
|
61
|
+
|
62
|
+
@sandbox.environments.concat %w(corge corge plugh)
|
63
|
+
entry.update
|
64
|
+
|
65
|
+
assert_equal %w(corge plugh), entry.environments
|
66
|
+
|
67
|
+
entry.update :foo => :bar
|
68
|
+
entry.update :bar => :baz
|
69
|
+
|
70
|
+
assert_equal({ :foo => :bar, :bar => :baz }, entry.options)
|
71
|
+
|
72
|
+
entry.update :args => "--first"
|
73
|
+
entry.update :args => "--second"
|
74
|
+
assert_equal "--second", entry.options[:args]
|
75
|
+
end
|
76
|
+
|
77
|
+
def e *args
|
78
|
+
Isolate::Entry.new @sandbox, *args
|
79
|
+
end
|
80
|
+
|
81
|
+
Spec = Struct.new :name, :version
|
82
|
+
|
83
|
+
def spec name, version
|
84
|
+
Spec.new name, Gem::Version.new(version)
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
require "isolate/test"
|
2
|
+
|
3
|
+
class TestIsolateSandbox < Isolate::Test
|
4
|
+
WITH_HOE = "test/fixtures/with-hoe"
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@sandbox = sandbox
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_activate
|
12
|
+
@sandbox = sandbox :path => WITH_HOE
|
13
|
+
|
14
|
+
refute_loaded_spec "hoe"
|
15
|
+
@sandbox.gem "hoe"
|
16
|
+
|
17
|
+
result = @sandbox.activate
|
18
|
+
assert_equal @sandbox, result
|
19
|
+
assert_loaded_spec "hoe"
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_activate_environment_explicit
|
23
|
+
@sandbox = sandbox :path => WITH_HOE
|
24
|
+
|
25
|
+
@sandbox.gem "rubyforge"
|
26
|
+
@sandbox.environment(:borg) { gem "hoe" }
|
27
|
+
@sandbox.activate :borg
|
28
|
+
|
29
|
+
assert_loaded_spec "hoe"
|
30
|
+
assert_loaded_spec "rubyforge"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_activate_environment_implicit
|
34
|
+
s = sandbox :path => WITH_HOE
|
35
|
+
|
36
|
+
s.gem "rubyforge"
|
37
|
+
s.environment(:borg) { gem "hoe" }
|
38
|
+
|
39
|
+
s.activate
|
40
|
+
refute_loaded_spec "hoe"
|
41
|
+
assert_loaded_spec "rubyforge"
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_activate_install
|
45
|
+
s = sandbox :path => WITH_HOE, :install => true
|
46
|
+
s.gem "foo"
|
47
|
+
|
48
|
+
# rescuing because activate, well, actually tries to activate
|
49
|
+
begin; s.activate; rescue Gem::LoadError; end
|
50
|
+
|
51
|
+
assert_equal ["foo", Gem::Requirement.default],
|
52
|
+
Gem::DependencyInstaller.value.shift
|
53
|
+
end
|
54
|
+
|
55
|
+
# TODO: cleanup with 2 versions of same gem, 1 activated
|
56
|
+
# TODO: install with 1 older version, 1 new gem to be installed
|
57
|
+
|
58
|
+
def test_cleanup
|
59
|
+
s = sandbox :path => WITH_HOE, :install => true, :cleanup => true
|
60
|
+
s.activate # no gems on purpose
|
61
|
+
|
62
|
+
expected = [["hoe", "2.3.3", WITH_HOE],
|
63
|
+
["rake", "0.8.7", WITH_HOE],
|
64
|
+
["rubyforge", "1.0.4", WITH_HOE]]
|
65
|
+
|
66
|
+
assert_equal expected, Gem::Uninstaller.value
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_disable
|
70
|
+
home, path, bin = ENV.values_at "GEM_HOME", "GEM_PATH", "PATH"
|
71
|
+
load_path = $LOAD_PATH.dup
|
72
|
+
|
73
|
+
@sandbox.enable
|
74
|
+
|
75
|
+
refute_equal home, ENV["GEM_HOME"]
|
76
|
+
refute_equal path, ENV["GEM_PATH"]
|
77
|
+
refute_equal bin, ENV["PATH"]
|
78
|
+
|
79
|
+
refute_equal load_path, $LOAD_PATH
|
80
|
+
|
81
|
+
result = @sandbox.disable
|
82
|
+
assert_same @sandbox, result
|
83
|
+
|
84
|
+
assert_equal home, ENV["GEM_HOME"]
|
85
|
+
assert_equal path, ENV["GEM_PATH"]
|
86
|
+
assert_equal bin, ENV["PATH"]
|
87
|
+
assert_equal load_path, $LOAD_PATH
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_enable
|
91
|
+
refute_empty Gem.find_files("hoe.rb"),
|
92
|
+
"There's a hoe.rb somewhere in the current env."
|
93
|
+
|
94
|
+
assert_same @sandbox, @sandbox.enable
|
95
|
+
|
96
|
+
assert_equal @sandbox.path, ENV["GEM_PATH"]
|
97
|
+
assert_equal @sandbox.path, ENV["GEM_HOME"]
|
98
|
+
assert ENV["PATH"].include?(File.join(@sandbox.path, "bin")), "in path"
|
99
|
+
|
100
|
+
assert_equal [], Gem.find_files("hoe.rb"),
|
101
|
+
"Can't find hoe.rb now, 'cause we're activated!"
|
102
|
+
|
103
|
+
assert_empty Gem.loaded_specs
|
104
|
+
assert_equal [@sandbox.path], Gem.path
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_enable_idempotent_path_env
|
108
|
+
bin = File.join @sandbox.path, "bin"
|
109
|
+
path = ENV["PATH"] = [bin, ENV["PATH"]].join(File::PATH_SEPARATOR)
|
110
|
+
|
111
|
+
@sandbox.enable
|
112
|
+
assert_equal path, ENV["PATH"]
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_idempotent_rubyopt_env
|
116
|
+
@sandbox.enable
|
117
|
+
rubyopt = ENV["RUBYOPT"]
|
118
|
+
@sandbox.disable
|
119
|
+
|
120
|
+
refute_equal rubyopt, ENV["RUBYOPT"]
|
121
|
+
|
122
|
+
ENV["RUBYOPT"] = rubyopt
|
123
|
+
@sandbox.enable
|
124
|
+
assert_equal rubyopt, ENV["RUBYOPT"]
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_environment
|
128
|
+
@sandbox.gem "none"
|
129
|
+
|
130
|
+
@sandbox.environment "test", "ci" do
|
131
|
+
gem "test-ci"
|
132
|
+
|
133
|
+
environment "production" do
|
134
|
+
gem "test-ci-production"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
none, test_ci, test_ci_production = @sandbox.entries
|
139
|
+
|
140
|
+
assert_equal [], none.environments
|
141
|
+
assert_equal %w(test ci), test_ci.environments
|
142
|
+
assert_equal %w(test ci production), test_ci_production.environments
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_gem
|
146
|
+
g = @sandbox.gem "foo"
|
147
|
+
assert_includes @sandbox.entries, g
|
148
|
+
|
149
|
+
assert_equal "foo", g.name
|
150
|
+
assert_equal Gem::Requirement.create(">= 0"), g.requirement
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_gem_multi_calls
|
154
|
+
g = @sandbox.gem "foo"
|
155
|
+
g2 = @sandbox.gem "foo", :foo => :bar
|
156
|
+
|
157
|
+
@sandbox.gem "foo", :bar => :baz
|
158
|
+
|
159
|
+
assert_same g, g2
|
160
|
+
assert_equal :bar, g.options[:foo]
|
161
|
+
assert_equal :baz, g.options[:bar]
|
162
|
+
|
163
|
+
@sandbox.gem "foo", "> 1.7"
|
164
|
+
assert_equal Gem::Requirement.new("> 1.7"), g.requirement
|
165
|
+
|
166
|
+
@sandbox.environment :corge do
|
167
|
+
gem "foo"
|
168
|
+
end
|
169
|
+
|
170
|
+
@sandbox.environment :plurgh do
|
171
|
+
gem "foo"
|
172
|
+
end
|
173
|
+
|
174
|
+
assert_equal %w(corge plurgh), g.environments
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_gem_multi_requirements
|
178
|
+
g = @sandbox.gem "foo", "= 1.0", "< 2.0"
|
179
|
+
assert_equal Gem::Requirement.create(["= 1.0", "< 2.0"]), g.requirement
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_gem_options
|
183
|
+
g = @sandbox.gem "foo", :source => "somewhere"
|
184
|
+
assert_equal "somewhere", g.options[:source]
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_initialize_defaults
|
188
|
+
s = Isolate::Sandbox.new
|
189
|
+
|
190
|
+
assert_equal [], s.entries
|
191
|
+
assert_equal [], s.environments
|
192
|
+
assert_match(/tmp\/isolate/, s.path)
|
193
|
+
|
194
|
+
assert s.cleanup?
|
195
|
+
assert s.install?
|
196
|
+
assert s.system?
|
197
|
+
assert s.verbose?
|
198
|
+
assert s.multiruby?
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_initialize_override_defaults
|
202
|
+
s = Isolate::Sandbox.new :path => "x", :cleanup => false,
|
203
|
+
:install => false, :system => false,
|
204
|
+
:verbose => false, :multiruby => false
|
205
|
+
|
206
|
+
assert_equal File.expand_path("x"), s.path
|
207
|
+
|
208
|
+
refute s.cleanup?
|
209
|
+
refute s.install?
|
210
|
+
refute s.system?
|
211
|
+
refute s.verbose?
|
212
|
+
refute s.multiruby?
|
213
|
+
end
|
214
|
+
|
215
|
+
# First the specifically requested file, then the block (if given),
|
216
|
+
# THEN the local override file (if it exists).
|
217
|
+
|
218
|
+
def test_initialize_file_and_block
|
219
|
+
s = sandbox :file => "test/fixtures/override.rb" do
|
220
|
+
environment :foo do
|
221
|
+
gem "monkey", "2.0", :args => "--panic"
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
monkey = s.entries.first
|
226
|
+
|
227
|
+
assert_equal %w(foo bar), monkey.environments
|
228
|
+
assert_equal "--asplode", monkey.options[:args]
|
229
|
+
assert_equal Gem::Requirement.new("2.0"), monkey.requirement
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_options
|
233
|
+
@sandbox.options :hello => :monkey
|
234
|
+
assert_equal :monkey, @sandbox.options[:hello]
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_path
|
238
|
+
s = sandbox :multiruby => false do
|
239
|
+
path "tmp/foo"
|
240
|
+
end
|
241
|
+
|
242
|
+
assert_equal File.expand_path("tmp/foo"), s.path
|
243
|
+
|
244
|
+
v = RbConfig::CONFIG.values_at("ruby_install_name", "ruby_version").join "-"
|
245
|
+
s = sandbox :multiruby => true
|
246
|
+
p = File.expand_path("tmp/isolate/#{v}")
|
247
|
+
|
248
|
+
assert_equal p, s.path
|
249
|
+
|
250
|
+
s = sandbox :path => "tmp/isolate/#{v}", :multiruby => false
|
251
|
+
assert_equal p, s.path
|
252
|
+
end
|
253
|
+
|
254
|
+
def assert_loaded_spec name
|
255
|
+
assert Gem.loaded_specs[name],
|
256
|
+
"#{name} is a loaded gemspec, and it shouldn't be!"
|
257
|
+
end
|
258
|
+
|
259
|
+
def refute_loaded_spec name
|
260
|
+
refute Gem.loaded_specs[name],
|
261
|
+
"#{name} is NOT a loaded gemspec, and it should be!"
|
262
|
+
end
|
263
|
+
|
264
|
+
def sandbox *args, &block
|
265
|
+
opts = {
|
266
|
+
:install => false,
|
267
|
+
:system => false,
|
268
|
+
:verbose => false,
|
269
|
+
:multiruby => false
|
270
|
+
}
|
271
|
+
|
272
|
+
opts.merge! args.pop if Hash === args.last
|
273
|
+
Isolate::Sandbox.new opts, &block
|
274
|
+
end
|
275
|
+
end
|