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.
@@ -1,3 +1,3 @@
1
1
  module Sandbox
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -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 = "http://github.com/fesplugas/ruby-virtualenv"
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")
@@ -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( Sandbox::LoadedSandboxError )
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( :each ) do
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( :new ).raises( StandardError )
22
- Sandbox::CLI.expects( :handle_error ).with( instance_of( StandardError ) )
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( :parse ).with( ARGV ).returns( @instance )
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( :new ).returns( @instance )
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( :parse_args! )
38
- Sandbox::CLI.expects( :new ).returns( @instance )
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( :execute! )
44
- Sandbox::CLI.expects( :parse ).returns( @instance )
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( "spec test msg" )
52
- Sandbox::CLI.expects( :tell_unless_really_quiet ).once.with( regexp_matches( /^Sandbox error: spec test msg/ ) )
53
- Sandbox::CLI.handle_error( err )
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( "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 )
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( "spec test msg" )
64
- Sandbox::CLI.expects( :tell_unless_really_quiet ).once.with( 'Interrupted' )
65
- Sandbox::CLI.handle_error( err )
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( 'you should have implemented it, dummy' )
70
- Sandbox::CLI.expects( :raise ).once.with( err )
71
- Sandbox::CLI.handle_error( err )
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( :each ) do
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[ :gems ].should == []
82
+ @cli.options[:gems].should == []
83
83
  end
84
-
84
+
85
85
  describe "instance calling parse_args!" do
86
- def processor( *args ); lambda { @cli.parse_args!( args ) }; end
87
- def process( *args ); processor( *args ).call; end
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[ :original_args ].should == []
93
- @cli.options[ :args ].should == []
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( :tell_unless_really_quiet ).with( Sandbox::VERSION )
101
- processor( arg ).should raise_error( SystemExit ) { |error| error.status.should == 0 }
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
- # @cli.stubs(:puts)
108
- @cli.expects( :tell_unless_really_quiet ).with( Sandbox::VERSION ).times(2)
109
- processor( arg, '-x' ).should raise_error( SystemExit ) { |error| error.status.should == 0 }
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( :tell_unless_really_quiet ).with( instance_of( OptionParser ) )
117
- processor( arg ).should raise_error( SystemExit ) { |error| error.status.should == 0 }
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( :tell_unless_really_quiet ).with( instance_of( OptionParser ) ).times(2)
124
- processor( arg, '-x' ).should raise_error( SystemExit ) { |error| error.status.should == 0 }
125
- processor( arg, 'unknown' ).should raise_error( SystemExit ) { |error| error.status.should == 0 }
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( :tell_unless_really_quiet )
132
- @cli.expects( :long_help )
133
- processor( arg ).should raise_error( SystemExit ) { |error| error.status.should == 0 }
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( :increase_verbosity )
140
- process( arg )
141
- @cli.options[ :original_args ].should == [ arg ]
142
- @cli.options[ :args ].should == []
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
- [ [ '-v', '-v' ], [ '--verbose', '--verbose' ] ].each do |args|
144
+
145
+ [['-v', '-v'], ['--verbose', '--verbose'] ].each do |args|
147
146
  it "should increase verbosity twice with '#{args.join(' ')}'" do
148
- Sandbox.expects( :increase_verbosity ).times(2)
149
- process( *args )
150
- @cli.options[ :original_args ].should == args
151
- @cli.options[ :args ].should == []
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( '-g' ).should raise_error( Sandbox::ParseError )
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 = [ '-g', 'somegem,anothergem' ]
161
- process( *args )
162
- @cli.options[ :original_args ].should == args
163
- @cli.options[ :args ].should == []
164
- @cli.options[ :gems ].should == [ 'somegem', 'anothergem' ]
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( '-n' )
169
- @cli.options[ :original_args ].should == [ '-n' ]
170
- @cli.options[ :args ].should == []
171
- @cli.options[ :gems ].should == []
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 = [ '/path/to/somewhere' ]
176
- process( *args )
177
- @cli.options[ :original_args ].should == args
178
- @cli.options[ :args ].should == args
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 = [ '-v', '/path/to/somewhere' ]
183
- process( *args )
184
- @cli.options[ :original_args ].should == args
185
- @cli.options[ :args ].should == [ args.last ]
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( '-x' ).
192
- should raise_error( Sandbox::ParseError ) { |error| error.message.should =~ /-x\b/ }
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[ :args ] = []
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[ :args ] = [ 'one', 'two' ]
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( :gems )
213
- @cli.options[ :args ] = [ 'one' ]
214
- installer = mock( 'Installer', :populate )
215
- Sandbox::Installer.expects( :new ).with( { :target => 'one' } ).returns( installer )
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( "\n" ).size.should be > 20
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
@@ -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( 'msg' ).message.should == 'Sandbox error: msg'
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( 'testing', [ 1, 2, 3, 4 ] ).
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( 'testing', "1, 2, 3, 4" ).
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( 'testing', [] ).
28
- message.should =~ /testing$/
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( :each ) do
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( opts )
14
- installer.options[ :somewhere ].should be_true
15
- installer.options[ :nowhere ].should be_false
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( opts )
26
- @installer.expects( :resolve_target ).with( path ).once.then.returns( path )
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( :tell )
37
- @installer.stubs( :target ).returns( '/tmp/sandbox' )
38
- @installer.expects( :create_directories )
39
- @installer.expects( :install_scripts )
40
- @installer.expects( :install_gemrc )
41
- @installer.expects( :install_gems )
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( :each ) do
44
+ before(:each) do
49
45
  @path = '/some/new/target'
50
46
  @installer = Sandbox::Installer.new
51
- @installer.stubs( :target ).returns( @path )
47
+ @installer.stubs(:target).returns(@path)
52
48
  end
53
49
  it "should create sandbox directory structure" do
54
- FileUtils.expects( :mkdir_p ).with( @path + '/rubygems/bin' )
55
- FileUtils.stubs( :ln_s )
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( :mkdir_p )
61
- FileUtils.expects( :ln_s ).with( @path + '/rubygems/bin', @path + '/bin' )
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( :each ) do
63
+ before(:each) do
69
64
  @path = '/some/new/target'
70
65
  @installer = Sandbox::Installer.new
71
- @installer.stubs( :target ).returns( @path )
66
+ @installer.stubs(:target).returns(@path)
72
67
  end
73
-
68
+
74
69
  it "should read template file" do
75
- File.expects( :read ).with( regexp_matches( /templates\/activate\.erb/ ) ).returns( '<%= target %>' )
76
- File.stubs( :open )
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( :read ).returns( '<%= target %>' )
83
- File.expects( :open ).with( @path + '/bin/activate', 'w' ).yields( file )
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( :each ) do
85
+ before(:each) do
92
86
  @path = '/some/new/target'
93
87
  @installer = Sandbox::Installer.new
94
- @installer.stubs( :target ).returns( @path )
88
+ @installer.stubs(:target).returns(@path)
95
89
  end
96
-
90
+
97
91
  it "should read template file" do
98
- File.expects( :read ).with( regexp_matches( /templates\/gemrc\.erb/ ) ).returns( '' )
99
- File.stubs( :open )
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( :read ).returns( 'gemrc' )
106
- File.expects( :open ).with( @path + '/.gemrc', 'w' ).yields( file )
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( :each ) do
115
- @installer = Sandbox::Installer.new( :gems => [ 'mygem' ] )
116
- @installer.stubs( :setup_sandbox_env )
117
- @installer.stubs( :restore_sandbox_env )
118
- @installer.stubs( :tell )
119
- @installer.stubs( :tell_unless_really_quiet )
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
- # it "should skip install when network is not available" do
123
- # Ping.expects( :pingecho ).with( 'gems.rubyforge.org' ).returns( false )
124
- # @installer.install_gems.should be_false
125
- # end
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( :shell_out ).with( 'gem install mygem' ).returns( [ true, 'blah' ] )
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( :shell_out ).with( 'gem install mygem' ).returns( [ false, 'blah' ] )
134
- @installer.expects( :tell_unless_really_quiet ).with( regexp_matches( /failed/ ) )
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( :each ) do
133
+ before(:each) do
142
134
  @path = '/absolute/path/to/parent'
143
135
  @installer = Sandbox::Installer.new
144
- @installer.stubs( :fix_path ).returns( @path )
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( :exists? ).with( @path ).returns( true )
149
- lambda { @installer.resolve_target( @path ) }.should raise_error( Sandbox::Error )
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( :exists? ).with( @path ).returns( false )
154
- @installer.expects( :check_path! ).with( '/absolute/path/to' ).returns( true )
155
- @installer.resolve_target( @path ).should == @path
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( :exists? ).with( @path ).returns( false )
160
- @installer.expects( :check_path! ).with( '/absolute/path/to' ).returns( false )
161
- @installer.expects( :check_path! ).with( '/absolute/path' ).returns( false )
162
- @installer.expects( :check_path! ).with( '/absolute' ).returns( true )
163
- @installer.resolve_target( @path ).should == @path
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( :fix_path ).returns( '/absolute' )
168
- @installer.expects( :check_path! ).with( '/' ).returns( false )
169
- lambda { @installer.resolve_target( '/absolute' ) }.should raise_error( RuntimeError )
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( :each ) do
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( :directory? ).with( @path ).returns( true )
182
- File.expects( :writable? ).with( @path ).returns( false )
183
- lambda { @installer.check_path!( @path ) }.should raise_error( Sandbox::Error )
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( :directory? ).with( @path ).returns( false )
188
- File.expects( :exists? ).with( @path ).returns( true )
189
- lambda { @installer.check_path!( @path ) }.should raise_error( Sandbox::Error )
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( :directory? ).with( @path ).returns( false )
194
- File.expects( :exists? ).with( @path ).returns( false )
195
- @installer.check_path!( @path ).should be_false
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( :directory? ).with( @path ).returns( true )
200
- File.expects( :writable? ).with( @path ).returns( true )
201
- @installer.check_path!( @path ).should == true
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( path ).should == 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( :pwd ).returns( abs_path )
206
+ FileUtils.expects(:pwd).returns(abs_path)
217
207
  @installer = Sandbox::Installer.new
218
- @installer.fix_path( path ).should == abs_path + '/' + path
208
+ @installer.fix_path(path).should == abs_path + '/' + path
219
209
  end
220
210
  end
221
-
222
- # shell_out( cmd )
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( 'true' )
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( 'false' )
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( 'ls -d /' )
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( 'ls -d / 1>/dev/null' )
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( :target ).returns( 'dummypath' )
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 in_dir( dir = tmppath )
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( dir )
278
+ Dir.chdir(dir)
279
279
  yield
280
280
  ensure
281
- Dir.chdir( old_pwd )
281
+ Dir.chdir(old_pwd)
282
282
  end
283
283
  end
284
-
285
- before( :each ) do
284
+
285
+ before(:each) do
286
286
  mktmppath
287
287
  end
288
-
289
- after( :each ) do
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( :target => target )
295
+ @installer = Sandbox::Installer.new(:target => target)
296
296
  @installer.create_directories
297
- File.directory?( target + '/rubygems/bin' ).should be_true
298
- File.symlink?( target + '/bin' ).should be_true
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