ruby-virtualenv 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ Autotest.add_hook :initialize do |at|
2
+
3
+ # Ignore the ._* files TextMate likes to leave about.
4
+ at.add_exception(/\/\._[^\/]*$/)
5
+
6
+ %w{ .git .svn svn-commit .DS_Store
7
+ .autotest Rakefile Capfile README doc
8
+ spec/spec.opts spec/rcov.opts
9
+ }.each { |exception| at.add_exception( exception ) }
10
+
11
+ at.find_directories = [ 'lib', 'spec' ]
12
+
13
+ end
@@ -0,0 +1,6 @@
1
+ pkg
2
+ doc
3
+ coverage
4
+ tmp
5
+ Manifest
6
+ .DS_Store
@@ -0,0 +1,17 @@
1
+ v0.5.0 Forked and renamed the project
2
+ Current rubygem name "sandbox" has already been taken, so we have
3
+ renamed the project to "ruby-virtualenv".
4
+
5
+ Cleaned and refactored code.
6
+
7
+ Updated gem stuff.
8
+
9
+ v0.2.0 Functional basic version.
10
+ Requires rubygems and only installs environment (with optional gem installs).
11
+
12
+ v0.1.2 Branched fullversion from master.
13
+ Full version will include ruby and rubygems installs.
14
+
15
+ v0.1.1 Adding rspec and cucumber
16
+
17
+ v0.1.0 First version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby-virtualenv.gemspec
4
+ gemspec
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby-virtualenv (0.5.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ metaclass (0.0.1)
11
+ mocha (0.10.0)
12
+ metaclass (~> 0.0.1)
13
+ rspec (2.6.0)
14
+ rspec-core (~> 2.6.0)
15
+ rspec-expectations (~> 2.6.0)
16
+ rspec-mocks (~> 2.6.0)
17
+ rspec-core (2.6.4)
18
+ rspec-expectations (2.6.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.6.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ mocha (~> 0.10.0)
27
+ rspec (~> 2.6.0)
28
+ ruby-virtualenv!
@@ -0,0 +1,120 @@
1
+ Sandbox
2
+ =======
3
+
4
+ * http://github.com/nkryptic/sandbox
5
+
6
+ DESCRIPTION:
7
+ ------------
8
+
9
+ Inspired by Python's [virtualenv](http://pypi.python.org/pypi/virtualenv)
10
+ project, Ruby-Virtualenv is a utility to create sandboxed Ruby/Rubygems
11
+ environments.
12
+
13
+ It is meant to address the following issues:
14
+
15
+ * Conflicts with unspecified gem dependency versions.
16
+ * Applications can have their own gem repositories.
17
+ * Permissions for installing your own gems.
18
+ * Ability to try gems out without installing into your global repository.
19
+ * A Simple way to enable this.
20
+
21
+ Running from your own gem repositories is fairly straight-forward, but
22
+ managing the necessary environment is a pain. This utility will create
23
+ a new environment which may be activated by the script `bin/activate` in
24
+ your sandbox directory.
25
+
26
+ Run the script with the following to enable your new environment:
27
+
28
+ $ source bin/activate
29
+
30
+ When you want to leave the environment:
31
+
32
+ $ deactivate
33
+
34
+ NOTES:
35
+ ------
36
+
37
+ * It creates an environment that has its own installation directory for Gems.
38
+ * It doesn't share gems with other sandbox environments.
39
+ * It (optionally) doesn't use the globally installed gems either.
40
+ * It will use a local to the sandbox .gemrc file
41
+
42
+ FEATURES/PROBLEMS:
43
+ ------------------
44
+
45
+ Activating your sandbox environment will change your HOME directory
46
+ temporarily to the sandbox directory. Other environment variables are
47
+ set to enable this funtionality, so if you may experience odd behavior.
48
+ Everything should be reset when you deactivate the sandbox.
49
+
50
+ USAGE:
51
+ ------
52
+
53
+ Create a new virtualenv (verbose output by default):
54
+
55
+ $ ruby-virtualenv ~/.ruby-virtualenvs/my-new-sandbox
56
+ creating new sandbox in /home/nkryptic/ruby-projects/my-new-sandbox
57
+ installing activation script
58
+ installing .gemrc
59
+ installing gems:
60
+ nothing to do
61
+
62
+ Create a new sandbox with no output:
63
+
64
+ $ ruby-virtualenv ~/.ruby-virtualenvs/my-new-sandbox -q
65
+
66
+ Create a new sandbox with specific gems:
67
+
68
+ $ ruby-virtualenv ~/.ruby-virtualenvs/my-new-sandbox -g rake,rails
69
+ creating new sandbox in /home/nkryptic/ruby-projects/my-new-sandbox
70
+ installing activation script
71
+ installing .gemrc
72
+ installing gems:
73
+ gem: rake
74
+ gem: rails
75
+
76
+ FUTURE PLANS:
77
+ -------------
78
+
79
+ I hope to expand the full version branch to allow for installing both
80
+ rubygems and ruby as part of the sandbox. This would enable experimentation
81
+ with different versions of both and exclude the requirement on needing
82
+ rubygems in the first place.
83
+
84
+ REQUIREMENTS:
85
+ -------------
86
+
87
+ * ruby
88
+ * rubygems
89
+
90
+ INSTALL:
91
+ --------
92
+
93
+ $ gem install ruby-virtualenv
94
+
95
+ LICENSE:
96
+ --------
97
+
98
+ (The MIT License)
99
+
100
+ Copyright (c) 2011 Francesc Esplugas
101
+ Copyright (c) 2008 Jacob Radford
102
+
103
+ Permission is hereby granted, free of charge, to any person obtaining
104
+ a copy of this software and associated documentation files (the
105
+ 'Software'), to deal in the Software without restriction, including
106
+ without limitation the rights to use, copy, modify, merge, publish,
107
+ distribute, sublicense, and/or sell copies of the Software, and to
108
+ permit persons to whom the Software is furnished to do so, subject to
109
+ the following conditions:
110
+
111
+ The above copyright notice and this permission notice shall be
112
+ included in all copies or substantial portions of the Software.
113
+
114
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
115
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
116
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
117
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
118
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
119
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
120
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/TODO ADDED
@@ -0,0 +1,68 @@
1
+ TODO: fix dependencies in rake files
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
+ TODO: user config
29
+ * set list of ruby variants to query?
30
+ * list of gems to install
31
+ ~/.sandbox/config
32
+ TODO: allow for install of ruby/rubygems
33
+ * how
34
+ * select dynamically?
35
+ * preset in config file?
36
+ * MRI, JRuby, Rubinius?
37
+ * each would have their own install method
38
+ * rubygems install would vary then
39
+ TODO: perhaps the following could be added to the activate script???
40
+ # function not_sourced() {
41
+ # ## ZSH source check
42
+ # test -n "$ZSH_NAME" -a "$HISTCMD" = "0" && return 0
43
+ # ## BASH source check
44
+ # test "`basename $1 2>/dev/null`" = "activate" && return 0
45
+ # ## script was not sourced
46
+ # return 1
47
+ # }
48
+ # function exit_with_warning() {
49
+ # echo "You must source this script (ie. source bin/activate)"
50
+ # exit 1
51
+ # }
52
+ # not_sourced $0 && exit_with_warning
53
+ # unset not_sourced
54
+ # unset exit_with_warning
55
+
56
+ # OTHER WAYS
57
+ # ====
58
+ # ONLY WORKS FOR BASH
59
+ # if [[ "$BASH_SOURCE" == "$0" ]]
60
+ # then
61
+ # echo "script was executed, not sourced"
62
+ # fi
63
+ # ====
64
+ # COULD WORK FOR BASH:
65
+ # if [ -n `readlink -f $0` ]; then
66
+ # echo "script was executed, not sourced"
67
+ # fi
68
+
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'sandbox/cli'
6
+ Sandbox::CLI.execute(ARGV)
@@ -0,0 +1,13 @@
1
+ Feature: Development processes of newgem itself (rake tasks)
2
+
3
+ As a Newgem maintainer or contributor
4
+ I want rake tasks to maintain and release the gem
5
+ So that I can spend time on the tests and code, and not excessive time on maintenance processes
6
+
7
+ Scenario: Generate RubyGem
8
+ Given this project is active project folder
9
+ And 'pkg' folder is deleted
10
+ When task 'rake gem' is invoked
11
+ Then folder 'pkg' is created
12
+ And file with name matching 'pkg/*.gem' is created else you should run "rake manifest" to fix this
13
+ And gem spec key 'rdoc_options' contains /--mainREADME.rdoc/
@@ -0,0 +1,174 @@
1
+ def in_project_folder(&block)
2
+ project_folder = @active_project_folder || @tmp_root
3
+ FileUtils.chdir(project_folder, &block)
4
+ end
5
+
6
+ def in_home_folder(&block)
7
+ FileUtils.chdir(@home_path, &block)
8
+ end
9
+
10
+ Given %r{^a safe folder} do
11
+ FileUtils.rm_rf @tmp_root = File.dirname(__FILE__) + "/../../tmp"
12
+ FileUtils.mkdir_p @tmp_root
13
+ FileUtils.mkdir_p @home_path = File.expand_path(File.join(@tmp_root, "home"))
14
+ @lib_path = File.expand_path(File.dirname(__FILE__) + '/../../lib')
15
+ Given "env variable $HOME set to '#{@home_path}'"
16
+ end
17
+
18
+ Given %r{^this project is active project folder} do
19
+ Given "a safe folder"
20
+ @active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
21
+ end
22
+
23
+ Given %r{^env variable \$([\w_]+) set to '(.*)'} do |env_var, value|
24
+ ENV[env_var] = value
25
+ end
26
+
27
+ def force_local_lib_override(project_name = @project_name)
28
+ rakefile = File.read(File.join(project_name, 'Rakefile'))
29
+ File.open(File.join(project_name, 'Rakefile'), "w+") do |f|
30
+ f << "$:.unshift('#{@lib_path}')\n"
31
+ f << rakefile
32
+ end
33
+ end
34
+
35
+ def setup_active_project_folder project_name
36
+ @active_project_folder = File.join(@tmp_root, project_name)
37
+ @project_name = project_name
38
+ end
39
+
40
+ Given %r{'(.*)' folder is deleted} do |folder|
41
+ in_project_folder do
42
+ FileUtils.rm_rf folder
43
+ end
44
+ end
45
+
46
+ When %r{^'(.*)' generator is invoked with arguments '(.*)'$} do |generator, arguments|
47
+ FileUtils.chdir(@active_project_folder) do
48
+ if Object.const_defined?("APP_ROOT")
49
+ APP_ROOT.replace(FileUtils.pwd)
50
+ else
51
+ APP_ROOT = FileUtils.pwd
52
+ end
53
+ run_generator(generator, arguments.split(' '), SOURCES)
54
+ end
55
+ end
56
+
57
+ When %r{run executable '(.*)' with arguments '(.*)'} do |executable, arguments|
58
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
59
+ FileUtils.chdir(@active_project_folder) do
60
+ system "ruby #{executable} #{arguments} > #{@stdout}"
61
+ end
62
+ end
63
+
64
+ When %r{^task 'rake (.*)' is invoked$} do |task|
65
+ @stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
66
+ FileUtils.chdir(@active_project_folder) do
67
+ system "rake #{task} --trace > #{@stdout} 2> #{@stdout}"
68
+ end
69
+ end
70
+
71
+ Then %r{^folder '(.*)' is created} do |folder|
72
+ in_project_folder do
73
+ File.exists?(folder).should be_true
74
+ end
75
+ end
76
+
77
+ Then %r{^file '(.*)' (is|is not) created} do |file, is|
78
+ in_project_folder do
79
+ File.exists?(file).should(is == 'is' ? be_true : be_false)
80
+ end
81
+ end
82
+
83
+ Then %r{^file with name matching '(.*)' is created} do |pattern|
84
+ in_project_folder do
85
+ Dir[pattern].should_not be_empty
86
+ end
87
+ end
88
+
89
+ Then %r{gem file '(.*)' and generated file '(.*)' should be the same} do |gem_file, project_file|
90
+ File.exists?(gem_file).should be_true
91
+ File.exists?(project_file).should be_true
92
+ gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
93
+ project_file_contents = File.read(File.join(@active_project_folder, project_file))
94
+ project_file_contents.should == gem_file_contents
95
+ end
96
+
97
+ Then %r{^output same as contents of '(.*)'$} do |file|
98
+ expected_output = File.read(File.join(File.dirname(__FILE__) + "/../expected_outputs", file))
99
+ actual_output = File.read(File.dirname(__FILE__) + "/../../tmp/#{@stdout}")
100
+ actual_output.should == expected_output
101
+ end
102
+
103
+ Then %r{^(does|does not) invoke generator '(.*)'$} do |does_invoke, generator|
104
+ actual_output = File.read(File.dirname(__FILE__) + "/../../tmp/#{@stdout}")
105
+ does_invoke == "does" ?
106
+ actual_output.should(match(/dependency\s+#{generator}/)) :
107
+ actual_output.should_not(match(/dependency\s+#{generator}/))
108
+ end
109
+
110
+ Then %r{help options '(.*)' and '(.*)' are displayed} do |opt1, opt2|
111
+ actual_output = File.read(@stdout)
112
+ actual_output.should match(/#{opt1}/)
113
+ actual_output.should match(/#{opt2}/)
114
+ end
115
+
116
+ Then %r{^output (does|does not) match \/(.*)\/} do |does, regex|
117
+ actual_output = File.read(@stdout)
118
+ (does == 'does') ?
119
+ actual_output.should(match(/#{regex}/)) :
120
+ actual_output.should_not(match(/#{regex}/))
121
+ end
122
+
123
+ Then %r{^contents of file '(.*)' (does|does not) match \/(.*)\/} do |file, does, regex|
124
+ in_project_folder do
125
+ actual_output = File.read(file)
126
+ (does == 'does') ?
127
+ actual_output.should(match(/#{regex}/)) :
128
+ actual_output.should_not(match(/#{regex}/))
129
+ end
130
+ end
131
+
132
+ Then %r{^all (\d+) tests pass} do |expected_test_count|
133
+ expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
134
+ actual_output = File.read(@stdout)
135
+ actual_output.should match(expected)
136
+ end
137
+
138
+ Then %r{^all (\d+) examples pass} do |expected_test_count|
139
+ expected = %r{^#{expected_test_count} examples?, 0 failures}
140
+ actual_output = File.read(@stdout)
141
+ actual_output.should match(expected)
142
+ end
143
+
144
+ Then %r{^yaml file '(.*)' contains (\{.*\})} do |file, yaml|
145
+ in_project_folder do
146
+ yaml = eval yaml
147
+ YAML.load(File.read(file)).should == yaml
148
+ end
149
+ end
150
+
151
+ Then %r{^Rakefile can display tasks successfully} do
152
+ @stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
153
+ FileUtils.chdir(@active_project_folder) do
154
+ system "rake -T > #{@stdout} 2> #{@stdout}"
155
+ end
156
+ actual_output = File.read(@stdout)
157
+ actual_output.should match(/^rake\s+\w+\s+#\s.*/)
158
+ end
159
+
160
+ Then %r{^task 'rake (.*)' is executed successfully} do |task|
161
+ @stdout.should_not be_nil
162
+ actual_output = File.read(@stdout)
163
+ actual_output.should_not match(/^Don't know how to build task '#{task}'/)
164
+ actual_output.should_not match(/Error/i)
165
+ end
166
+
167
+ Then %r{^gem spec key '(.*)' contains \/(.*)\/} do |key, regex|
168
+ in_project_folder do
169
+ gem_file = Dir["pkg/*.gem"].first
170
+ gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
171
+ spec_value = gem_spec.send(key.to_sym)
172
+ spec_value.to_s.should match(/#{regex}/)
173
+ end
174
+ end