nkryptic-sandbox 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -80,7 +80,7 @@ the first place.
80
80
  == REQUIREMENTS:
81
81
 
82
82
  * ruby
83
- * rubygems (currently, until full version complete)
83
+ * rubygems
84
84
 
85
85
  == INSTALL:
86
86
 
data/Rakefile CHANGED
@@ -15,9 +15,9 @@ begin
15
15
  p.email = "nkryptic@gmail.com"
16
16
  p.ignore_pattern = [ "tmp/*", "script/*" ]
17
17
  p.development_dependencies = [
18
- 'echoe ~> 3.0',
19
- 'rspec ~> 1.1.0',
20
- 'mocha ~> 0.9',
18
+ # 'echoe ~> 3.0',
19
+ # 'rspec ~> 1.1.0',
20
+ # 'mocha ~> 0.9',
21
21
  ]
22
22
  # p.dependencies = ['ParseTree >=2.1.1', 'ruby2ruby >=1.1.8']
23
23
  end
data/TODO CHANGED
@@ -1,14 +1,69 @@
1
1
 
2
- * allow gem versions to be specified when installing
3
- * better documentation
4
- * of the codebase
5
- * more specs
6
- * why not try for 100% coverage
7
- * improve ui output
8
- * use verbosity level
9
- * include more messages about status
10
- * move to ui class?
11
- * user config
12
- * list of gems to install
13
- ~/.sandbox/config
14
-
2
+ TODO: put in timeout when installing gems
3
+ TODO: check for network connection
4
+ TODO: perhaps look in installed rubygems cache first
5
+ TODO: make rubygems dependency fail immediately and gracefully?
6
+ * in bin/sandbox?
7
+ TODO: replace backticks for gem installs with open4 library?
8
+ TODO: allow for sandbox to be rerun against existing sandbox to update it?
9
+ TODO: test against various OS platforms
10
+ * BSD
11
+ * OSX
12
+ * Gentoo
13
+ * Debian/Ubuntu
14
+ * Could it work on Windows?
15
+ * ?
16
+ TODO: test against other shells
17
+ * csh
18
+ * zsh
19
+ TODO: test against other ruby versions?
20
+ * jruby
21
+ TODO: allow gem versions to be specified when installing
22
+ TODO: better documentation
23
+ * of the codebase
24
+ * in the readme
25
+ TODO: improve ui output
26
+ * use verbosity level
27
+ * include more messages about status
28
+ * move to ui class?
29
+ TODO: user config
30
+ * set list of ruby variants to query?
31
+ * list of gems to install
32
+ ~/.sandbox/config
33
+ TODO: allow for install of ruby/rubygems
34
+ * how
35
+ * select dynamically?
36
+ * preset in config file?
37
+ * MRI, JRuby, Rubinius?
38
+ * each would have their own install method
39
+ * rubygems install would vary then
40
+ TODO: perhaps the following could be added to the activate script???
41
+ # function not_sourced() {
42
+ # ## ZSH source check
43
+ # test -n "$ZSH_NAME" -a "$HISTCMD" = "0" && return 0
44
+ # ## BASH source check
45
+ # test "`basename $1 2>/dev/null`" = "activate_sandbox" && return 0
46
+ # ## script was not sourced
47
+ # return 1
48
+ # }
49
+ # function exit_with_warning() {
50
+ # echo "You must source this script (ie. source bin/activate_sandbox)"
51
+ # exit 1
52
+ # }
53
+ # not_sourced $0 && exit_with_warning
54
+ # unset not_sourced
55
+ # unset exit_with_warning
56
+
57
+ # OTHER WAYS
58
+ # ====
59
+ # ONLY WORKS FOR BASH
60
+ # if [[ "$BASH_SOURCE" == "$0" ]]
61
+ # then
62
+ # echo "script was executed, not sourced"
63
+ # fi
64
+ # ====
65
+ # COULD WORK FOR BASH:
66
+ # if [ -n `readlink -f $0` ]; then
67
+ # echo "script was executed, not sourced"
68
+ # fi
69
+
data/lib/sandbox/cli.rb CHANGED
@@ -122,9 +122,9 @@ module Sandbox
122
122
  end
123
123
  end
124
124
 
125
- def show_help
126
- puts parser
127
- end
125
+ # def show_help
126
+ # puts parser
127
+ # end
128
128
 
129
129
  def long_help
130
130
  unindent( <<-HELP )
@@ -140,14 +140,14 @@ module Sandbox
140
140
 
141
141
  Running from your own gem repositories is fairly straight-forward, but
142
142
  managing the necessary environment is a pain. This utility will create a new
143
- environment which may be activated by the script `bin/activate` in your
144
- sandbox directory.
143
+ environment which may be activated by the script `bin/activate_sandbox` in
144
+ your sandbox directory.
145
145
 
146
146
  Run the script with the following to enable your new environment:
147
- $ source bin/activate
147
+ $ source bin/activate_sandbox
148
148
 
149
149
  When you want to leave the environment:
150
- $ deactivate
150
+ $ deactivate_sandbox
151
151
 
152
152
  NOTES:
153
153
  1. It creates an environment that has its own installation directory for Gems.
@@ -21,6 +21,7 @@ module Sandbox
21
21
 
22
22
  def initialize( msg=nil )
23
23
  msg ||= "You cannot run sandbox from a loaded sandbox environment"
24
+ super msg
24
25
  end
25
26
 
26
27
  end
@@ -99,10 +99,10 @@ module Sandbox
99
99
  end
100
100
 
101
101
  def restore_sandbox_env
102
- ENV.update( @old_env )
103
- # ENV[ 'HOME' ] = @old_env[ 'HOME' ]
104
- # ENV[ 'GEM_HOME' ] = @old_env[ 'GEM_HOME' ]
105
- # ENV[ 'GEM_PATH' ] = @old_env[ 'GEM_PATH' ]
102
+ # ENV.update( @old_env )
103
+ ENV[ 'HOME' ] = @old_env[ 'HOME' ]
104
+ ENV[ 'GEM_HOME' ] = @old_env[ 'GEM_HOME' ]
105
+ ENV[ 'GEM_PATH' ] = @old_env[ 'GEM_PATH' ]
106
106
  end
107
107
 
108
108
  def resolve_target( path )
@@ -117,7 +117,7 @@ module Sandbox
117
117
  if check_path!( base )
118
118
  break
119
119
  elsif base == '/'
120
- break
120
+ raise "something is seriously wrong; we should never get here"
121
121
  end
122
122
  end
123
123
  return path
@@ -89,3 +89,9 @@ export PS1
89
89
  if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
90
90
  hash -r
91
91
  fi
92
+
93
+
94
+ #
95
+ #
96
+ # Thanks to the virtualenv developers ( http://pypi.python.org/pypi/virtualenv )
97
+ #
@@ -5,7 +5,7 @@ module Sandbox
5
5
 
6
6
  MAJOR = 0
7
7
  MINOR = 2
8
- TINY = 0
8
+ TINY = 1
9
9
 
10
10
  STRING = [ MAJOR, MINOR, TINY ].join( '.' )
11
11
 
data/sandbox.gemspec CHANGED
@@ -2,18 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{sandbox}
5
-
6
- s.version = "0.2.0"
5
+ s.version = "0.2.1"
7
6
 
8
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
9
8
  s.authors = ["Jacob Radford"]
10
- s.date = %q{2008-12-01}
9
+ s.date = %q{2008-12-05}
11
10
  s.default_executable = %q{sandbox}
12
11
  s.description = %q{Create virtual ruby/rubygems sandboxes.}
13
12
  s.email = %q{nkryptic@gmail.com}
14
13
  s.executables = ["sandbox"]
15
14
  s.extra_rdoc_files = ["CHANGELOG", "TODO", "README.rdoc", "tasks/rspec.rake", "tasks/cucumber.rake", "tasks/gem.rake", "tasks/dcov.rake", "lib/sandbox.rb", "lib/sandbox/installer.rb", "lib/sandbox/cli.rb", "lib/sandbox/templates/activate_sandbox.erb", "lib/sandbox/version.rb", "lib/sandbox/errors.rb", "bin/sandbox"]
16
- s.files = ["sandbox.gemspec", "CHANGELOG", "TODO", "spec/sandbox/cli_spec.rb", "spec/sandbox/installer_spec.rb", "spec/sandbox_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "Manifest", "features/steps/common.rb", "features/steps/env.rb", "features/development.feature", "README.rdoc", "tasks/rspec.rake", "tasks/cucumber.rake", "tasks/gem.rake", "tasks/dcov.rake", "Rakefile", "lib/sandbox.rb", "lib/sandbox/installer.rb", "lib/sandbox/cli.rb", "lib/sandbox/templates/activate_sandbox.erb", "lib/sandbox/version.rb", "lib/sandbox/errors.rb", "bin/sandbox"]
15
+ s.files = ["sandbox.gemspec", "CHANGELOG", "TODO", "spec/sandbox/errors_spec.rb", "spec/sandbox/cli_spec.rb", "spec/sandbox/installer_spec.rb", "spec/sandbox_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "Manifest", "features/steps/common.rb", "features/steps/env.rb", "features/development.feature", "README.rdoc", "tasks/rspec.rake", "tasks/cucumber.rake", "tasks/gem.rake", "tasks/dcov.rake", "Rakefile", "lib/sandbox.rb", "lib/sandbox/installer.rb", "lib/sandbox/cli.rb", "lib/sandbox/templates/activate_sandbox.erb", "lib/sandbox/version.rb", "lib/sandbox/errors.rb", "bin/sandbox"]
17
16
  s.has_rdoc = true
18
17
  s.homepage = %q{http://github.com/nkryptic/sandbox}
19
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sandbox", "--main", "README.rdoc"]
@@ -27,17 +26,8 @@ Gem::Specification.new do |s|
27
26
  s.specification_version = 2
28
27
 
29
28
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
30
- s.add_development_dependency(%q<echoe>, ["~> 0", "= 3.0"])
31
- s.add_development_dependency(%q<rspec>, ["~> 0", "= 1.1.0"])
32
- s.add_development_dependency(%q<mocha>, ["~> 0", "= 0.9"])
33
29
  else
34
- s.add_dependency(%q<echoe>, ["~> 0", "= 3.0"])
35
- s.add_dependency(%q<rspec>, ["~> 0", "= 1.1.0"])
36
- s.add_dependency(%q<mocha>, ["~> 0", "= 0.9"])
37
30
  end
38
31
  else
39
- s.add_dependency(%q<echoe>, ["~> 0", "= 3.0"])
40
- s.add_dependency(%q<rspec>, ["~> 0", "= 1.1.0"])
41
- s.add_dependency(%q<mocha>, ["~> 0", "= 0.9"])
42
32
  end
43
33
  end
@@ -47,6 +47,32 @@ describe Sandbox::CLI do
47
47
  end
48
48
  end
49
49
 
50
+ describe "handling errors" do
51
+ it "should just print Sandbox::Error message" do
52
+ err = Sandbox::Error.new( "spec test msg" )
53
+ Sandbox::CLI.expects( :puts ).once.with( regexp_matches( /^Sandbox error: spec test msg/ ) )
54
+ Sandbox::CLI.handle_error( err )
55
+ end
56
+
57
+ it "should just print wrapped StandardError message" do
58
+ err = StandardError.new( "spec test msg" )
59
+ Sandbox::CLI.expects( :puts ).once.with( regexp_matches( /^Error: spec test msg/ ) )
60
+ Sandbox::CLI.handle_error( err )
61
+ end
62
+
63
+ it "should have simple message for Interrupt" do
64
+ err = Interrupt.new( "spec test msg" )
65
+ Sandbox::CLI.expects( :puts ).once.with( 'Interrupted' )
66
+ Sandbox::CLI.handle_error( err )
67
+ end
68
+
69
+ it "should reraise other errors" do
70
+ err = NotImplementedError.new( 'you should have implemented it, dummy' )
71
+ Sandbox::CLI.expects( :raise ).once.with( err )
72
+ Sandbox::CLI.handle_error( err )
73
+ end
74
+ end
75
+
50
76
  describe "a new instance" do
51
77
 
52
78
  before( :each ) do
@@ -193,6 +219,16 @@ describe Sandbox::CLI do
193
219
 
194
220
  end
195
221
 
222
+ describe "instance calling long_help" do
223
+ it "should return a long descriptive string" do
224
+ @cli.long_help.split( "\n" ).size.should be > 20
225
+ @cli.long_help.should =~ /activate_sandbox/
226
+ @cli.long_help.should =~ /deactivate_sandbox/
227
+ @cli.long_help.should =~ /NOTES:/
228
+ @cli.long_help.should =~ /WARNINGS:/
229
+ end
230
+ end
231
+
196
232
  end
197
233
 
198
234
  end
@@ -0,0 +1,34 @@
1
+
2
+ require File.dirname( __FILE__ ) + '/../spec_helper.rb'
3
+
4
+ describe 'new', Sandbox::Error do
5
+ it "should wrap it's message with 'Sandbox error'" do
6
+ Sandbox::Error.new( 'msg' ).message.should == 'Sandbox error: msg'
7
+ end
8
+ end
9
+
10
+ describe 'new', Sandbox::LoadedSandboxError do
11
+ it "should have informative default msg" do
12
+ Sandbox::LoadedSandboxError.new.message.should =~ /loaded sandbox/
13
+ end
14
+ end
15
+
16
+ describe 'new', Sandbox::ParseError do
17
+ it "should accept reason with array" do
18
+ Sandbox::ParseError.new( 'testing', [ 1, 2, 3, 4 ] ).
19
+ message.should =~ /testing => 1 2 3 4/
20
+ end
21
+
22
+ it "should accept reason with string" do
23
+ Sandbox::ParseError.new( 'testing', "1, 2, 3, 4" ).
24
+ message.should =~ /testing => 1, 2, 3, 4/
25
+ end
26
+
27
+ it "should fall back to reason alone" do
28
+ Sandbox::ParseError.new( 'testing', [] ).
29
+ message.should =~ /testing$/
30
+ Sandbox::ParseError.new( 'testing', '' ).
31
+ message.should =~ /testing$/
32
+ end
33
+ end
34
+
@@ -130,6 +130,12 @@ describe Sandbox::Installer, "(mocked)" do
130
130
  @installer.expects( :check_path! ).with( '/absolute' ).returns( true )
131
131
  @installer.resolve_target( @path ).should == @path
132
132
  end
133
+
134
+ it "should have emergency safeguard for dirname on root" do
135
+ @installer.stubs( :fix_path ).returns( '/absolute' )
136
+ @installer.expects( :check_path! ).with( '/' ).returns( false )
137
+ lambda { @installer.resolve_target( '/absolute' ) }.should raise_error( RuntimeError )
138
+ end
133
139
  end
134
140
 
135
141
  # check_path!( path )
@@ -180,6 +186,52 @@ describe Sandbox::Installer, "(mocked)" do
180
186
  @installer.fix_path( path ).should == abs_path + '/' + path
181
187
  end
182
188
  end
189
+
190
+ # shell_out( cmd )
191
+ describe "when shell_out called" do
192
+ it "should record true when successful" do
193
+ @installer = Sandbox::Installer.new
194
+ result = @installer.shell_out( '/bin/true' )
195
+ result.first.should be_true
196
+ end
197
+
198
+ it "should record false when unsuccessful" do
199
+ @installer = Sandbox::Installer.new
200
+ result = @installer.shell_out( '/bin/false' )
201
+ result.first.should_not be_true
202
+ end
203
+
204
+ it "should record std output" do
205
+ @installer = Sandbox::Installer.new
206
+ result = @installer.shell_out( 'ls -d /' )
207
+ result.last.chomp.should == '/'
208
+ end
209
+
210
+ it "should ignore std error" do
211
+ @installer = Sandbox::Installer.new
212
+ result = @installer.shell_out( 'ls -d / 1>&2' )
213
+ result.last.chomp.should == ''
214
+ end
215
+ end
216
+
217
+ describe "setup and restore sandbox env called" do
218
+ it "should set and restore the environment" do
219
+ orig_home = ENV[ 'HOME' ]
220
+ orig_gem_home = ENV[ 'GEM_HOME' ]
221
+ orig_gem_path = ENV[ 'GEM_PATH' ]
222
+ @installer = Sandbox::Installer.new
223
+ @installer.stubs( :target ).returns( 'dummypath' )
224
+
225
+ @installer.setup_sandbox_env
226
+ ENV[ 'HOME' ].should == 'dummypath'
227
+ ENV[ 'GEM_HOME' ].should == 'dummypath/rubygems'
228
+ ENV[ 'GEM_PATH' ].should == 'dummypath/rubygems'
229
+ @installer.restore_sandbox_env
230
+ ENV[ 'HOME' ].should == orig_home
231
+ ENV[ 'GEM_HOME' ].should == orig_gem_home
232
+ ENV[ 'GEM_PATH' ].should == orig_gem_path
233
+ end
234
+ end
183
235
  end
184
236
  end
185
237
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nkryptic-sandbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Radford
@@ -9,45 +9,10 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-01 00:00:00 -08:00
12
+ date: 2008-12-05 00:00:00 -08:00
13
13
  default_executable: sandbox
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: echoe
17
- version_requirement:
18
- version_requirements: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ~>
21
- - !ruby/object:Gem::Version
22
- version: "0"
23
- - - "="
24
- - !ruby/object:Gem::Version
25
- version: "3.0"
26
- version:
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ~>
33
- - !ruby/object:Gem::Version
34
- version: "0"
35
- - - "="
36
- - !ruby/object:Gem::Version
37
- version: 1.1.0
38
- version:
39
- - !ruby/object:Gem::Dependency
40
- name: mocha
41
- version_requirement:
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ~>
45
- - !ruby/object:Gem::Version
46
- version: "0"
47
- - - "="
48
- - !ruby/object:Gem::Version
49
- version: "0.9"
50
- version:
14
+ dependencies: []
15
+
51
16
  description: Create virtual ruby/rubygems sandboxes.
52
17
  email: nkryptic@gmail.com
53
18
  executables:
@@ -73,6 +38,7 @@ files:
73
38
  - sandbox.gemspec
74
39
  - CHANGELOG
75
40
  - TODO
41
+ - spec/sandbox/errors_spec.rb
76
42
  - spec/sandbox/cli_spec.rb
77
43
  - spec/sandbox/installer_spec.rb
78
44
  - spec/sandbox_spec.rb