ruby-virtualenv 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +32 -63
- data/Rakefile +8 -0
- data/lib/sandbox/cli.rb +9 -13
- data/lib/sandbox/errors.rb +2 -2
- data/lib/sandbox/installer.rb +46 -72
- data/lib/sandbox/templates/activate.erb +2 -16
- data/lib/sandbox/version.rb +1 -1
- data/ruby-virtualenv.gemspec +1 -1
- data/spec/sandbox/cli_spec.rb +114 -116
- data/spec/sandbox/errors_spec.rb +5 -9
- data/spec/sandbox/installer_spec.rb +131 -133
- data/spec/sandbox/output_spec.rb +39 -39
- data/spec/sandbox_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +6 -12
- data/features/development.feature +0 -13
- data/features/steps/common.rb +0 -174
- data/features/steps/env.rb +0 -10
data/lib/sandbox/version.rb
CHANGED
data/ruby-virtualenv.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["nkryptic@gmail.com", "francesc.esplugas@gmail.com"]
|
7
7
|
gem.description = %q{Create virtual ruby/rubygems environments.}
|
8
8
|
gem.summary = %q{Create virtual ruby/rubygems environments.}
|
9
|
-
gem.homepage = "
|
9
|
+
gem.homepage = "https://github.com/fesplugas/ruby-virtualenv"
|
10
10
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
12
12
|
gem.files = `git ls-files`.split("\n")
|
data/spec/sandbox/cli_spec.rb
CHANGED
@@ -2,233 +2,231 @@ require 'spec_helper'
|
|
2
2
|
require 'sandbox/cli'
|
3
3
|
|
4
4
|
describe Sandbox::CLI do
|
5
|
-
|
5
|
+
|
6
6
|
it "should raise an error when running from a loaded sandbox" do
|
7
7
|
begin
|
8
8
|
ENV[ 'SANDBOX' ] = 'something'
|
9
|
-
lambda { Sandbox::CLI.verify_environment! }.should raise_error(
|
9
|
+
lambda { Sandbox::CLI.verify_environment! }.should raise_error(Sandbox::LoadedSandboxError)
|
10
10
|
ensure
|
11
11
|
ENV[ 'SANDBOX' ] = nil
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
describe "calling execute" do
|
16
|
-
before(
|
16
|
+
before(:each) do
|
17
17
|
@instance = stub_everything()
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "should handle all errors" do
|
21
|
-
Sandbox::CLI.stubs(
|
22
|
-
Sandbox::CLI.expects(
|
21
|
+
Sandbox::CLI.stubs(:new).raises(StandardError)
|
22
|
+
Sandbox::CLI.expects(:handle_error).with(instance_of(StandardError))
|
23
23
|
Sandbox::CLI.execute
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should attempt to parse ARGV by default" do
|
27
|
-
Sandbox::CLI.expects(
|
27
|
+
Sandbox::CLI.expects(:parse).with(ARGV).returns(@instance)
|
28
28
|
Sandbox::CLI.execute
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
it "should create a new instance" do
|
32
|
-
Sandbox::CLI.expects(
|
32
|
+
Sandbox::CLI.expects(:new).returns(@instance)
|
33
33
|
Sandbox::CLI.execute
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should call parse_args! on the new instance" do
|
37
|
-
@instance.expects(
|
38
|
-
Sandbox::CLI.expects(
|
37
|
+
@instance.expects(:parse_args!)
|
38
|
+
Sandbox::CLI.expects(:new).returns(@instance)
|
39
39
|
Sandbox::CLI.execute
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it "should run the instance" do
|
43
|
-
@instance.expects(
|
44
|
-
Sandbox::CLI.expects(
|
43
|
+
@instance.expects(:execute!)
|
44
|
+
Sandbox::CLI.expects(:parse).returns(@instance)
|
45
45
|
Sandbox::CLI.execute
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
describe "handling errors" do
|
50
50
|
it "should just print Sandbox::Error message" do
|
51
|
-
err = Sandbox::Error.new(
|
52
|
-
Sandbox::CLI.expects(
|
53
|
-
Sandbox::CLI.handle_error(
|
51
|
+
err = Sandbox::Error.new("spec test msg")
|
52
|
+
Sandbox::CLI.expects(:tell_unless_really_quiet).once.with(regexp_matches(/^spec test msg/))
|
53
|
+
Sandbox::CLI.handle_error(err)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "should just print wrapped StandardError message" do
|
57
|
-
err = StandardError.new(
|
58
|
-
Sandbox::CLI.expects(
|
59
|
-
Sandbox::CLI.handle_error(
|
57
|
+
err = StandardError.new("spec test msg")
|
58
|
+
Sandbox::CLI.expects(:tell_unless_really_quiet).once.with(regexp_matches(/^Error: spec test msg/))
|
59
|
+
Sandbox::CLI.handle_error(err)
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
it "should have simple message for Interrupt" do
|
63
|
-
err = Interrupt.new(
|
64
|
-
Sandbox::CLI.expects(
|
65
|
-
Sandbox::CLI.handle_error(
|
63
|
+
err = Interrupt.new("spec test msg")
|
64
|
+
Sandbox::CLI.expects(:tell_unless_really_quiet).once.with('Interrupted')
|
65
|
+
Sandbox::CLI.handle_error(err)
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it "should reraise other errors" do
|
69
|
-
err = NotImplementedError.new(
|
70
|
-
Sandbox::CLI.expects(
|
71
|
-
Sandbox::CLI.handle_error(
|
69
|
+
err = NotImplementedError.new('you should have implemented it, dummy')
|
70
|
+
Sandbox::CLI.expects(:raise).once.with(err)
|
71
|
+
Sandbox::CLI.handle_error(err)
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
describe "a new instance" do
|
76
|
-
|
77
|
-
before(
|
76
|
+
|
77
|
+
before(:each) do
|
78
78
|
@cli = Sandbox::CLI.new
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "should have no default 'gems to install'" do
|
82
|
-
@cli.options[
|
82
|
+
@cli.options[:gems].should == []
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
describe "instance calling parse_args!" do
|
86
|
-
def processor(
|
87
|
-
def process(
|
88
|
-
|
86
|
+
def processor(*args); lambda { @cli.parse_args!(args) }; end
|
87
|
+
def process(*args); processor(*args).call; end
|
88
|
+
|
89
89
|
describe "using NO arguments" do
|
90
90
|
it "should use raise nothing" do
|
91
|
-
process
|
92
|
-
@cli.options[
|
93
|
-
@cli.options[
|
91
|
+
process
|
92
|
+
@cli.options[:original_args].should == []
|
93
|
+
@cli.options[:args].should == []
|
94
94
|
end
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
describe "using VALID arguments" do
|
98
98
|
[ '-V', '--version' ].each do |arg|
|
99
99
|
it "should print the version for switch '#{arg}'" do
|
100
|
-
@cli.expects(
|
101
|
-
processor(
|
100
|
+
@cli.expects(:tell_unless_really_quiet).with(Sandbox::VERSION)
|
101
|
+
processor(arg).should raise_error(SystemExit) { |error| error.status.should == 0 }
|
102
102
|
end
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
[ '-V', '--version' ].each do |arg|
|
106
106
|
it "should ignore additional arguments after '#{arg}'" do
|
107
|
-
|
108
|
-
|
109
|
-
processor(
|
110
|
-
processor( arg, 'unknown' ).should raise_error( SystemExit ) { |error| error.status.should == 0 }
|
107
|
+
@cli.expects(:tell_unless_really_quiet).with(Sandbox::VERSION).times(2)
|
108
|
+
processor(arg, '-x').should raise_error(SystemExit) { |error| error.status.should == 0 }
|
109
|
+
processor(arg, 'unknown').should raise_error(SystemExit) { |error| error.status.should == 0 }
|
111
110
|
end
|
112
111
|
end
|
113
|
-
|
112
|
+
|
114
113
|
[ '-h', '--help' ].each do |arg|
|
115
114
|
it "should show help for '#{arg}'" do
|
116
|
-
@cli.expects(
|
117
|
-
processor(
|
115
|
+
@cli.expects(:tell_unless_really_quiet).with(instance_of(OptionParser))
|
116
|
+
processor(arg).should raise_error(SystemExit) { |error| error.status.should == 0 }
|
118
117
|
end
|
119
118
|
end
|
120
|
-
|
119
|
+
|
121
120
|
[ '-h', '--help' ].each do |arg|
|
122
121
|
it "should ignore additional arguments after '#{arg}'" do
|
123
|
-
@cli.expects(
|
124
|
-
processor(
|
125
|
-
processor(
|
122
|
+
@cli.expects(:tell_unless_really_quiet).with(instance_of(OptionParser)).times(2)
|
123
|
+
processor(arg, '-x').should raise_error(SystemExit) { |error| error.status.should == 0 }
|
124
|
+
processor(arg, 'unknown').should raise_error(SystemExit) { |error| error.status.should == 0 }
|
126
125
|
end
|
127
126
|
end
|
128
|
-
|
127
|
+
|
129
128
|
[ '-H', '--long-help' ].each do |arg|
|
130
129
|
it "should show long help for '#{arg}'" do
|
131
|
-
@cli.expects(
|
132
|
-
@cli.expects(
|
133
|
-
processor(
|
130
|
+
@cli.expects(:tell_unless_really_quiet)
|
131
|
+
@cli.expects(:long_help)
|
132
|
+
processor(arg).should raise_error(SystemExit) { |error| error.status.should == 0 }
|
134
133
|
end
|
135
134
|
end
|
136
|
-
|
135
|
+
|
137
136
|
[ '-v', '--verbose' ].each do |arg|
|
138
137
|
it "should increase verbosity with '#{arg}'" do
|
139
|
-
Sandbox.expects(
|
140
|
-
process(
|
141
|
-
@cli.options[
|
142
|
-
@cli.options[
|
138
|
+
Sandbox.expects(:increase_verbosity)
|
139
|
+
process(arg)
|
140
|
+
@cli.options[:original_args].should == [arg]
|
141
|
+
@cli.options[:args].should == []
|
143
142
|
end
|
144
143
|
end
|
145
|
-
|
146
|
-
[
|
144
|
+
|
145
|
+
[['-v', '-v'], ['--verbose', '--verbose'] ].each do |args|
|
147
146
|
it "should increase verbosity twice with '#{args.join(' ')}'" do
|
148
|
-
Sandbox.expects(
|
149
|
-
process(
|
150
|
-
@cli.options[
|
151
|
-
@cli.options[
|
147
|
+
Sandbox.expects(:increase_verbosity).times(2)
|
148
|
+
process(*args)
|
149
|
+
@cli.options[:original_args].should == args
|
150
|
+
@cli.options[:args].should == []
|
152
151
|
end
|
153
152
|
end
|
154
|
-
|
153
|
+
|
155
154
|
it "should require additional arguments with switch '-g'" do
|
156
|
-
processor(
|
155
|
+
processor('-g').should raise_error(Sandbox::ParseError)
|
157
156
|
end
|
158
|
-
|
157
|
+
|
159
158
|
it "should set 'gems to install' with switch '-g'" do
|
160
|
-
args = [
|
161
|
-
process(
|
162
|
-
@cli.options[
|
163
|
-
@cli.options[
|
164
|
-
@cli.options[
|
159
|
+
args = ['-g', 'somegem,anothergem']
|
160
|
+
process(*args)
|
161
|
+
@cli.options[:original_args].should == args
|
162
|
+
@cli.options[:args].should == []
|
163
|
+
@cli.options[:gems].should == ['somegem', 'anothergem']
|
165
164
|
end
|
166
|
-
|
165
|
+
|
167
166
|
it "should clear 'gems to install' with switch '-n'" do
|
168
|
-
process(
|
169
|
-
@cli.options[
|
170
|
-
@cli.options[
|
171
|
-
@cli.options[
|
167
|
+
process('-n')
|
168
|
+
@cli.options[:original_args].should == ['-n']
|
169
|
+
@cli.options[:args].should == []
|
170
|
+
@cli.options[:gems].should == []
|
172
171
|
end
|
173
|
-
|
172
|
+
|
174
173
|
it "should store leftover arguments in options for arguments '/path/to/somewhere'" do
|
175
|
-
args = [
|
176
|
-
process(
|
177
|
-
@cli.options[
|
178
|
-
@cli.options[
|
174
|
+
args = ['/path/to/somewhere']
|
175
|
+
process(*args)
|
176
|
+
@cli.options[:original_args].should == args
|
177
|
+
@cli.options[:args].should == args
|
179
178
|
end
|
180
179
|
|
181
180
|
it "should store leftover arguments in options for arguments '-v /path/to/somewhere'" do
|
182
|
-
args = [
|
183
|
-
process(
|
184
|
-
@cli.options[
|
185
|
-
@cli.options[
|
181
|
+
args = ['-v', '/path/to/somewhere']
|
182
|
+
process(*args)
|
183
|
+
@cli.options[:original_args].should == args
|
184
|
+
@cli.options[:args].should == [args.last]
|
186
185
|
end
|
187
186
|
end
|
188
|
-
|
187
|
+
|
189
188
|
describe "using INVALID arguments" do
|
190
189
|
it "should exit with message for invalid switch '-x'" do
|
191
|
-
processor(
|
192
|
-
should raise_error(
|
190
|
+
processor('-x').
|
191
|
+
should raise_error(Sandbox::ParseError) { |error| error.message.should =~ /-x\b/ }
|
193
192
|
end
|
194
193
|
end
|
195
194
|
end
|
196
|
-
|
195
|
+
|
197
196
|
describe "instance calling execute!" do
|
198
197
|
def processor; lambda { @cli.execute! }; end
|
199
198
|
def process; processor.call; end
|
200
|
-
|
199
|
+
|
201
200
|
it "should raise error with no target specified" do
|
202
|
-
@cli.options[
|
201
|
+
@cli.options[:args] = []
|
203
202
|
processor.should raise_error
|
204
203
|
end
|
205
|
-
|
204
|
+
|
206
205
|
it "should raise error with more than one target" do
|
207
|
-
@cli.options[
|
206
|
+
@cli.options[:args] = ['one', 'two']
|
208
207
|
processor.should raise_error
|
209
208
|
end
|
210
|
-
|
209
|
+
|
211
210
|
it "should instantiate an Installer and call populate with one target" do
|
212
|
-
@cli.options.delete(
|
213
|
-
@cli.options[
|
214
|
-
installer = mock(
|
215
|
-
Sandbox::Installer.expects(
|
211
|
+
@cli.options.delete(:gems)
|
212
|
+
@cli.options[:args] = ['one']
|
213
|
+
installer = mock('Installer', :populate)
|
214
|
+
Sandbox::Installer.expects(:new).with({:target=>'one'}).returns(installer)
|
216
215
|
process
|
217
216
|
end
|
218
|
-
|
217
|
+
|
219
218
|
end
|
220
|
-
|
219
|
+
|
221
220
|
describe "instance calling long_help" do
|
222
221
|
it "should return a long descriptive string" do
|
223
|
-
@cli.long_help.split(
|
222
|
+
@cli.long_help.split("\n").size.should be > 20
|
224
223
|
@cli.long_help.should =~ /activate/
|
225
224
|
@cli.long_help.should =~ /deactivate/
|
226
225
|
@cli.long_help.should =~ /NOTES:/
|
227
226
|
@cli.long_help.should =~ /WARNINGS:/
|
228
227
|
end
|
229
228
|
end
|
230
|
-
|
229
|
+
|
231
230
|
end
|
232
|
-
|
233
|
-
end
|
234
231
|
|
232
|
+
end
|
data/spec/sandbox/errors_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'new', Sandbox::Error do
|
4
4
|
it "should wrap it's message with 'Sandbox error'" do
|
5
|
-
Sandbox::Error.new(
|
5
|
+
Sandbox::Error.new('msg').message.should == 'msg'
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
@@ -14,19 +14,15 @@ end
|
|
14
14
|
|
15
15
|
describe 'new', Sandbox::ParseError do
|
16
16
|
it "should accept reason with array" do
|
17
|
-
Sandbox::ParseError.new(
|
18
|
-
message.should =~ /testing => 1 2 3 4/
|
17
|
+
Sandbox::ParseError.new('testing', [1, 2, 3, 4]).message.should =~ /testing => 1 2 3 4/
|
19
18
|
end
|
20
19
|
|
21
20
|
it "should accept reason with string" do
|
22
|
-
Sandbox::ParseError.new(
|
23
|
-
message.should =~ /testing => 1, 2, 3, 4/
|
21
|
+
Sandbox::ParseError.new('testing', "1, 2, 3, 4").message.should =~ /testing => 1, 2, 3, 4/
|
24
22
|
end
|
25
23
|
|
26
24
|
it "should fall back to reason alone" do
|
27
|
-
Sandbox::ParseError.new(
|
28
|
-
|
29
|
-
Sandbox::ParseError.new( 'testing', '' ).
|
30
|
-
message.should =~ /testing$/
|
25
|
+
Sandbox::ParseError.new('testing', []).message.should =~ /testing$/
|
26
|
+
Sandbox::ParseError.new('testing', '').message.should =~ /testing$/
|
31
27
|
end
|
32
28
|
end
|
@@ -1,259 +1,249 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Sandbox::Installer, "(mocked)" do
|
4
|
-
|
5
|
-
before(
|
4
|
+
|
5
|
+
before(:each) do
|
6
6
|
Sandbox.instance_eval { instance_variables.each { |v| remove_instance_variable v } }
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
describe "creating an instance" do
|
10
|
-
# initialize( options={} )
|
11
10
|
it "should set it's options" do
|
12
11
|
opts = { :somewhere => true, :nowhere => false }
|
13
|
-
installer = Sandbox::Installer.new(
|
14
|
-
installer.options[
|
15
|
-
installer.options[
|
12
|
+
installer = Sandbox::Installer.new(opts)
|
13
|
+
installer.options[:somewhere].should be_true
|
14
|
+
installer.options[:nowhere].should be_false
|
16
15
|
end
|
17
16
|
end
|
18
|
-
|
17
|
+
|
19
18
|
describe "instance" do
|
20
|
-
# target
|
21
19
|
describe "when target called" do
|
22
20
|
it "should validate target directory once" do
|
23
21
|
path = '/some/new/target'
|
24
22
|
opts = { :target => path }
|
25
|
-
@installer = Sandbox::Installer.new(
|
26
|
-
@installer.expects(
|
23
|
+
@installer = Sandbox::Installer.new(opts)
|
24
|
+
@installer.expects(:resolve_target).with(path).once.then.returns(path)
|
27
25
|
@installer.target.should == path
|
28
26
|
@installer.target.should == path
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
32
|
-
# populate
|
33
30
|
describe "when populate called" do
|
34
31
|
it "should call all steps of populate process" do
|
35
32
|
@installer = Sandbox::Installer.new
|
36
|
-
@installer.stubs(
|
37
|
-
@installer.stubs(
|
38
|
-
@installer.expects(
|
39
|
-
@installer.expects(
|
40
|
-
@installer.expects(
|
41
|
-
@installer.expects(
|
33
|
+
@installer.stubs(:tell)
|
34
|
+
@installer.stubs(:target).returns('/tmp/sandbox')
|
35
|
+
@installer.expects(:create_directories)
|
36
|
+
@installer.expects(:install_scripts)
|
37
|
+
@installer.expects(:install_gemrc)
|
38
|
+
@installer.expects(:install_gems)
|
42
39
|
@installer.populate
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
46
|
-
# create_directories
|
47
43
|
describe "when create_directories called" do
|
48
|
-
before(
|
44
|
+
before(:each) do
|
49
45
|
@path = '/some/new/target'
|
50
46
|
@installer = Sandbox::Installer.new
|
51
|
-
@installer.stubs(
|
47
|
+
@installer.stubs(:target).returns(@path)
|
52
48
|
end
|
53
49
|
it "should create sandbox directory structure" do
|
54
|
-
FileUtils.expects(
|
55
|
-
FileUtils.stubs(
|
50
|
+
FileUtils.expects(:mkdir_p).with(@path + '/rubygems/bin')
|
51
|
+
FileUtils.stubs(:ln_s)
|
56
52
|
@installer.create_directories
|
57
53
|
end
|
58
54
|
|
59
55
|
it "should symlink gem bin directory" do
|
60
|
-
FileUtils.stubs(
|
61
|
-
FileUtils.expects(
|
56
|
+
FileUtils.stubs(:mkdir_p)
|
57
|
+
FileUtils.expects(:ln_s).with(@path + '/rubygems/bin', @path + '/bin')
|
62
58
|
@installer.create_directories
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
66
|
-
# install_scripts
|
67
62
|
describe "when install_scripts called" do
|
68
|
-
before(
|
63
|
+
before(:each) do
|
69
64
|
@path = '/some/new/target'
|
70
65
|
@installer = Sandbox::Installer.new
|
71
|
-
@installer.stubs(
|
66
|
+
@installer.stubs(:target).returns(@path)
|
72
67
|
end
|
73
|
-
|
68
|
+
|
74
69
|
it "should read template file" do
|
75
|
-
File.expects(
|
76
|
-
File.stubs(
|
70
|
+
File.expects(:read).with(regexp_matches(/templates\/activate\.erb/)).returns('<%= target %>')
|
71
|
+
File.stubs(:open)
|
77
72
|
@installer.install_scripts
|
78
73
|
end
|
79
|
-
|
74
|
+
|
80
75
|
it "should write out activate script to SANDBOX/bin/activate" do
|
81
76
|
file = StringIO.new
|
82
|
-
File.stubs(
|
83
|
-
File.expects(
|
77
|
+
File.stubs(:read).returns('<%= target %>')
|
78
|
+
File.expects(:open).with(@path + '/bin/activate', 'w').yields(file)
|
84
79
|
@installer.install_scripts
|
85
80
|
file.string.should == @path
|
86
81
|
end
|
87
82
|
end
|
88
|
-
|
89
|
-
# install_gemrc
|
83
|
+
|
90
84
|
describe "when install_gemrc called" do
|
91
|
-
before(
|
85
|
+
before(:each) do
|
92
86
|
@path = '/some/new/target'
|
93
87
|
@installer = Sandbox::Installer.new
|
94
|
-
@installer.stubs(
|
88
|
+
@installer.stubs(:target).returns(@path)
|
95
89
|
end
|
96
|
-
|
90
|
+
|
97
91
|
it "should read template file" do
|
98
|
-
File.expects(
|
99
|
-
File.stubs(
|
92
|
+
File.expects(:read).with(regexp_matches(/templates\/gemrc\.erb/)).returns('')
|
93
|
+
File.stubs(:open)
|
100
94
|
@installer.install_gemrc
|
101
95
|
end
|
102
|
-
|
96
|
+
|
103
97
|
it "should write out gemrc to SANDBOX/.gemrc" do
|
104
98
|
file = StringIO.new
|
105
|
-
File.stubs(
|
106
|
-
File.expects(
|
99
|
+
File.stubs(:read).returns('gemrc')
|
100
|
+
File.expects(:open).with(@path + '/.gemrc', 'w').yields(file)
|
107
101
|
@installer.install_gemrc
|
108
102
|
file.string.should == 'gemrc'
|
109
103
|
end
|
110
104
|
end
|
111
105
|
|
112
|
-
# install_gems
|
113
106
|
describe "when install_gems called" do
|
114
|
-
before(
|
115
|
-
@installer = Sandbox::Installer.new(
|
116
|
-
@installer.stubs(
|
117
|
-
@installer.stubs(
|
118
|
-
@installer.stubs(
|
119
|
-
@installer.stubs(
|
107
|
+
before(:each) do
|
108
|
+
@installer = Sandbox::Installer.new(:gems => [ 'mygem' ])
|
109
|
+
@installer.stubs(:setup_sandbox_env)
|
110
|
+
@installer.stubs(:restore_sandbox_env)
|
111
|
+
@installer.stubs(:tell)
|
112
|
+
@installer.stubs(:tell_unless_really_quiet)
|
120
113
|
end
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
114
|
+
|
115
|
+
xit "should skip install when network is not available" do
|
116
|
+
Ping.expects(:pingecho).with('gems.rubyforge.org').returns(false)
|
117
|
+
@installer.install_gems.should be_false
|
118
|
+
end
|
119
|
+
|
127
120
|
it "should install a good gem" do
|
128
|
-
@installer.expects(
|
121
|
+
@installer.expects(:shell_out).with('gem install mygem').returns([ true, 'blah' ])
|
129
122
|
@installer.install_gems
|
130
123
|
end
|
131
|
-
|
124
|
+
|
132
125
|
it "should gracefully handle a bad gem" do
|
133
|
-
@installer.expects(
|
134
|
-
@installer.expects(
|
126
|
+
@installer.expects(:shell_out).with('gem install mygem').returns([ false, 'blah' ])
|
127
|
+
@installer.expects(:tell_unless_really_quiet).with(regexp_matches(/failed/))
|
135
128
|
@installer.install_gems
|
136
129
|
end
|
137
130
|
end
|
138
131
|
|
139
|
-
# resolve_target( path )
|
140
132
|
describe "when resolve_target called" do
|
141
|
-
before(
|
133
|
+
before(:each) do
|
142
134
|
@path = '/absolute/path/to/parent'
|
143
135
|
@installer = Sandbox::Installer.new
|
144
|
-
@installer.stubs(
|
136
|
+
@installer.stubs(:fix_path).returns(@path)
|
145
137
|
end
|
146
|
-
|
138
|
+
|
147
139
|
it "should raise error when it path exists" do
|
148
|
-
File.expects(
|
149
|
-
lambda { @installer.resolve_target(
|
140
|
+
File.expects(:exists?).with(@path).returns(true)
|
141
|
+
lambda { @installer.resolve_target(@path) }.should raise_error(Sandbox::Error)
|
150
142
|
end
|
151
|
-
|
143
|
+
|
152
144
|
it "should return path when parent directory passes check_path!" do
|
153
|
-
File.expects(
|
154
|
-
@installer.expects(
|
155
|
-
@installer.resolve_target(
|
145
|
+
File.expects(:exists?).with(@path).returns(false)
|
146
|
+
@installer.expects(:check_path!).with('/absolute/path/to').returns(true)
|
147
|
+
@installer.resolve_target(@path).should == @path
|
156
148
|
end
|
157
|
-
|
149
|
+
|
158
150
|
it "should return path when any parent directory passes check_path!" do
|
159
|
-
File.expects(
|
160
|
-
@installer.expects(
|
161
|
-
@installer.expects(
|
162
|
-
@installer.expects(
|
163
|
-
@installer.resolve_target(
|
151
|
+
File.expects(:exists?).with(@path).returns(false)
|
152
|
+
@installer.expects(:check_path!).with('/absolute/path/to').returns(false)
|
153
|
+
@installer.expects(:check_path!).with('/absolute/path').returns(false)
|
154
|
+
@installer.expects(:check_path!).with('/absolute').returns(true)
|
155
|
+
@installer.resolve_target(@path).should == @path
|
164
156
|
end
|
165
|
-
|
157
|
+
|
166
158
|
it "should have emergency safeguard for dirname on root" do
|
167
|
-
@installer.stubs(
|
168
|
-
@installer.expects(
|
169
|
-
lambda { @installer.resolve_target(
|
159
|
+
@installer.stubs(:fix_path).returns('/absolute')
|
160
|
+
@installer.expects(:check_path!).with('/').returns(false)
|
161
|
+
lambda { @installer.resolve_target('/absolute') }.should raise_error(RuntimeError)
|
170
162
|
end
|
171
163
|
end
|
172
164
|
|
173
|
-
# check_path!( path )
|
174
165
|
describe "when check_path! called" do
|
175
|
-
before(
|
166
|
+
before(:each) do
|
176
167
|
@path = '/absolute/path/to/parent'
|
177
168
|
@installer = Sandbox::Installer.new
|
178
169
|
end
|
179
|
-
|
170
|
+
|
180
171
|
it "should raise error when it is not writable" do
|
181
|
-
File.expects(
|
182
|
-
File.expects(
|
183
|
-
lambda { @installer.check_path!(
|
172
|
+
File.expects(:directory?).with(@path).returns(true)
|
173
|
+
File.expects(:writable?).with(@path).returns(false)
|
174
|
+
lambda { @installer.check_path!(@path) }.should raise_error(Sandbox::Error)
|
184
175
|
end
|
185
|
-
|
176
|
+
|
186
177
|
it "should raise error when it is not a directory" do
|
187
|
-
File.expects(
|
188
|
-
File.expects(
|
189
|
-
lambda { @installer.check_path!(
|
178
|
+
File.expects(:directory?).with(@path).returns(false)
|
179
|
+
File.expects(:exists?).with(@path).returns(true)
|
180
|
+
lambda { @installer.check_path!(@path) }.should raise_error(Sandbox::Error)
|
190
181
|
end
|
191
|
-
|
182
|
+
|
192
183
|
it "should return false when it doesn't exist" do
|
193
|
-
File.expects(
|
194
|
-
File.expects(
|
195
|
-
@installer.check_path!(
|
184
|
+
File.expects(:directory?).with(@path).returns(false)
|
185
|
+
File.expects(:exists?).with(@path).returns(false)
|
186
|
+
@installer.check_path!(@path).should be_false
|
196
187
|
end
|
197
|
-
|
188
|
+
|
198
189
|
it "should return true when it can be created" do
|
199
|
-
File.expects(
|
200
|
-
File.expects(
|
201
|
-
@installer.check_path!(
|
190
|
+
File.expects(:directory?).with(@path).returns(true)
|
191
|
+
File.expects(:writable?).with(@path).returns(true)
|
192
|
+
@installer.check_path!(@path).should == true
|
202
193
|
end
|
203
194
|
end
|
204
195
|
|
205
|
-
# fix_path( path )
|
206
196
|
describe "when fix_path called" do
|
207
197
|
it "should not change absolute path" do
|
208
198
|
path = '/absolute/path/to/target'
|
209
199
|
@installer = Sandbox::Installer.new
|
210
|
-
@installer.fix_path(
|
200
|
+
@installer.fix_path(path).should == path
|
211
201
|
end
|
212
|
-
|
202
|
+
|
213
203
|
it "should make relative into absolute path" do
|
214
204
|
abs_path = '/absolute/working/directory'
|
215
205
|
path = 'relative/path/to/target'
|
216
|
-
FileUtils.expects(
|
206
|
+
FileUtils.expects(:pwd).returns(abs_path)
|
217
207
|
@installer = Sandbox::Installer.new
|
218
|
-
@installer.fix_path(
|
208
|
+
@installer.fix_path(path).should == abs_path + '/' + path
|
219
209
|
end
|
220
210
|
end
|
221
|
-
|
222
|
-
|
211
|
+
|
212
|
+
|
223
213
|
describe "when shell_out called" do
|
224
214
|
it "should record true when successful" do
|
225
215
|
@installer = Sandbox::Installer.new
|
226
|
-
result = @installer.shell_out(
|
216
|
+
result = @installer.shell_out('true')
|
227
217
|
result.first.should be_true
|
228
218
|
end
|
229
|
-
|
219
|
+
|
230
220
|
it "should record false when unsuccessful" do
|
231
221
|
@installer = Sandbox::Installer.new
|
232
|
-
result = @installer.shell_out(
|
222
|
+
result = @installer.shell_out('false')
|
233
223
|
result.first.should_not be_true
|
234
224
|
end
|
235
|
-
|
225
|
+
|
236
226
|
it "should record std output" do
|
237
227
|
@installer = Sandbox::Installer.new
|
238
|
-
result = @installer.shell_out(
|
228
|
+
result = @installer.shell_out('ls -d /')
|
239
229
|
result.last.chomp.should == '/'
|
240
230
|
end
|
241
|
-
|
231
|
+
|
242
232
|
it "should ignore std error" do
|
243
233
|
@installer = Sandbox::Installer.new
|
244
|
-
result = @installer.shell_out(
|
234
|
+
result = @installer.shell_out('ls -d / 1>/dev/null')
|
245
235
|
result.last.chomp.should == ''
|
246
236
|
end
|
247
237
|
end
|
248
|
-
|
238
|
+
|
249
239
|
describe "setup and restore sandbox env called" do
|
250
240
|
it "should set and restore the environment" do
|
251
241
|
orig_home = ENV[ 'HOME' ]
|
252
242
|
orig_gem_home = ENV[ 'GEM_HOME' ]
|
253
243
|
orig_gem_path = ENV[ 'GEM_PATH' ]
|
254
244
|
@installer = Sandbox::Installer.new
|
255
|
-
@installer.stubs(
|
256
|
-
|
245
|
+
@installer.stubs(:target).returns('dummypath')
|
246
|
+
|
257
247
|
@installer.setup_sandbox_env
|
258
248
|
ENV[ 'HOME' ].should == 'dummypath'
|
259
249
|
ENV[ 'GEM_HOME' ].should == 'dummypath/rubygems'
|
@@ -264,40 +254,48 @@ describe Sandbox::Installer, "(mocked)" do
|
|
264
254
|
ENV[ 'GEM_PATH' ].should == orig_gem_path
|
265
255
|
end
|
266
256
|
end
|
257
|
+
|
267
258
|
end
|
268
259
|
end
|
269
260
|
|
270
261
|
describe Sandbox::Installer, "(using tmpdir)" do
|
271
|
-
def tmppath() File.join( Dir.tmpdir, "sandbox_testing" ) end
|
272
|
-
def rmtmppath() FileUtils.rm_rf( tmppath ) end
|
273
|
-
def mktmppath() FileUtils.mkdir_p( tmppath ) end
|
274
262
|
|
275
|
-
def
|
263
|
+
def tmppath
|
264
|
+
File.join(Dir.tmpdir, "sandbox_testing")
|
265
|
+
end
|
266
|
+
|
267
|
+
def rmtmppath
|
268
|
+
FileUtils.rm_rf(tmppath)
|
269
|
+
end
|
270
|
+
|
271
|
+
def mktmppath
|
272
|
+
FileUtils.mkdir_p(tmppath)
|
273
|
+
end
|
274
|
+
|
275
|
+
def in_dir(dir = tmppath)
|
276
276
|
old_pwd = Dir.pwd
|
277
277
|
begin
|
278
|
-
Dir.chdir(
|
278
|
+
Dir.chdir(dir)
|
279
279
|
yield
|
280
280
|
ensure
|
281
|
-
Dir.chdir(
|
281
|
+
Dir.chdir(old_pwd)
|
282
282
|
end
|
283
283
|
end
|
284
|
-
|
285
|
-
before(
|
284
|
+
|
285
|
+
before(:each) do
|
286
286
|
mktmppath
|
287
287
|
end
|
288
|
-
|
289
|
-
after(
|
288
|
+
|
289
|
+
after(:each) do
|
290
290
|
rmtmppath
|
291
291
|
end
|
292
|
-
|
292
|
+
|
293
293
|
it "should create target directory structure" do
|
294
294
|
target = tmppath + '/target'
|
295
|
-
@installer = Sandbox::Installer.new(
|
295
|
+
@installer = Sandbox::Installer.new(:target => target)
|
296
296
|
@installer.create_directories
|
297
|
-
File.directory?(
|
298
|
-
File.symlink?(
|
297
|
+
File.directory?(target + '/rubygems/bin').should be_true
|
298
|
+
File.symlink?(target + '/bin').should be_true
|
299
299
|
end
|
300
|
-
end
|
301
|
-
|
302
300
|
|
303
|
-
|
301
|
+
end
|