rvm-capistrano 1.4.4 → 1.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/History.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 1.5.0.rc1 / 2013-08-18
2
+
3
+ * Thanks to @aspiers for the great work:
4
+ * add tests
5
+ * add mixed mode support
6
+ * add support for disabling `sudo` based on `:subject_class`
7
+
1
8
  ### 1.4.4 / 2013-08-14
2
9
 
3
10
  * cleaning, merge #83
data/README.md CHANGED
@@ -175,6 +175,7 @@ end
175
175
  - `:system` - RVM installed in `/usr/local`, multiuser installation
176
176
  - (some other values permitted for backwards compatability only)
177
177
 
178
+ - `:rvm_user` - arguments to pass to `rvm user`, to enable mixed mode (e.g. system rubies and user gemsets). Based on whether rvm_user includes :gemsets it also helps determine the correct path for importing/exporting gemsets, and similarly, whether to use sudo for gemset creation/deletion and other operations.
178
179
  - `:rvm_autolibs_flag` - control autolibs, read more `rvm help autolibs`
179
180
  - `:disable` - fully disable autolibs, limit automated tasks
180
181
  - `:read` - autolibs only in read only mode, do not change anything in system
@@ -16,7 +16,9 @@ rvm_with_capistrano do
16
16
 
17
17
  desc "Create application wrappers"
18
18
  rvm_task :create_wrappers do
19
- run_rvm("wrapper #{rvm_ruby_string_evaluated} --no-prefix --all", :with_rvm_group => true)
19
+ run_rvm("wrapper #{rvm_ruby_string_evaluated} --no-prefix --all",
20
+ :with_rvm_group => true,
21
+ :subject_class => :wrappers)
20
22
  end
21
23
 
22
24
  end
@@ -22,34 +22,57 @@ rvm_with_capistrano do
22
22
 
23
23
  # Let users set the type of their rvm install.
24
24
  _cset(:rvm_type, :user)
25
+ _cset(:rvm_user, [])
26
+ if rvm_type == :mixed
27
+ abort "When rvm_type is :mixed, you must also set rvm_user." if rvm_user.empty?
28
+ abort "rvm_user must be an Array of values, e.g. [ :gemsets ]" unless rvm_user.is_a? Array
29
+ valid = [ :gemsets, :rubies, :hooks, :pkgs, :wrappers ]
30
+ invalid = rvm_user - valid - [:all, :none ]
31
+ abort "Invalid value(s) in rvm_user: " + invalid.join(', ') unless invalid.empty?
32
+ if rvm_user.size > 1
33
+ abort "rvm_user cannot mix :none with other values." if rvm_user.include? :none
34
+ abort "rvm_user cannot mix :all with other values." if rvm_user.include? :all
35
+ elsif rvm_user == [ :all ]
36
+ set(:rvm_user) { valid }
37
+ end
38
+ else
39
+ if ! rvm_user.empty?
40
+ abort "rvm_user must not be set unless rvm_type is :mixed (was #{rvm_user})."
41
+ end
42
+ end
25
43
 
26
- # Define rvm_path
44
+ # Define rvm system and user paths
27
45
  # This is used in the default_shell command to pass the required variable to rvm-shell, allowing
28
46
  # rvm to boostrap using the proper path. This is being lost in Capistrano due to the lack of a
29
47
  # full environment.
48
+ _cset(:rvm_system_path, "/usr/local/rvm")
49
+ _cset(:rvm_user_path, "$HOME/.rvm")
50
+
30
51
  _cset(:rvm_path) do
31
52
  case rvm_type
32
- when :root, :system
33
- "/usr/local/rvm"
53
+ when :root, :system, :mixed
54
+ rvm_system_path
34
55
  when :local, :user, :default
35
- "$HOME/.rvm/"
56
+ rvm_user_path
36
57
  else
37
- rvm_type.to_s.empty? ? "$HOME/.rvm" : rvm_type.to_s
58
+ rvm_type.to_s.empty? ? rvm_user_path : rvm_type.to_s
38
59
  end
39
60
  end
40
61
 
41
62
  # Let users override the rvm_bin_path
42
- _cset(:rvm_bin_path) do
63
+ _cset(:rvm_bin_path) { "#{rvm_path}/bin" }
64
+
65
+ # Let users configure a path to export/import gemsets
66
+ _cset(:rvm_gemset_path) do
43
67
  case rvm_type
44
- when :root, :system
45
- "/usr/local/rvm/bin"
46
- when :local, :user, :default
47
- "$HOME/.rvm/bin"
68
+ when :root, :system, :local, :user, :default
69
+ rvm_path
70
+ when :mixed
71
+ rvm_user.include?(:gemsets) ? rvm_user_path : rvm_system_path
48
72
  else
49
- rvm_type.to_s.empty? ? "#{rvm_path}/bin" : rvm_type.to_s
50
- end
73
+ rvm_path
74
+ end + "/gemsets"
51
75
  end
52
-
53
76
  # evaluate :rvm_ruby_string => :local
54
77
  set :rvm_ruby_string_evaluated do
55
78
  value = fetch(:rvm_ruby_string, :default)
@@ -15,7 +15,9 @@ gemset can not be created when using :rvm_ruby_string => :#{ruby}
15
15
  "
16
16
  else
17
17
  if gemset
18
- run_rvm("rvm gemset create #{gemset}", :with_rvm_group => true, :with_ruby => ruby)
18
+ run_rvm("rvm gemset create #{gemset}",
19
+ :with_rvm_group => true, :with_ruby => ruby,
20
+ :subject_class => :gemsets)
19
21
  end
20
22
  end
21
23
  end
@@ -12,7 +12,9 @@ rvm_with_capistrano do
12
12
  raise "gemset can not be emptied when using :rvm_ruby_string => :#{ruby}"
13
13
  else
14
14
  if gemset
15
- run_rvm("rvm --force gemset empty #{gemset}", :with_ruby => ruby)
15
+ run_rvm("rvm --force gemset empty #{gemset}",
16
+ :with_rvm_group => true, :with_ruby => ruby,
17
+ :subject_class => :gemsets)
16
18
  end
17
19
  end
18
20
  end
@@ -5,12 +5,16 @@ rvm_with_capistrano do
5
5
 
6
6
  desc "Install a gem, 'cap rvm:install_gem GEM=my_gem'."
7
7
  rvm_task :install_gem do
8
- run_rvm("gem install #{ENV['GEM']}", :with_ruby => rvm_ruby_string_evaluated)
8
+ run_rvm("gem install #{ENV['GEM']}",
9
+ :with_ruby => rvm_ruby_string_evaluated,
10
+ :subject_class => :gemsets)
9
11
  end
10
12
 
11
13
  desc "Uninstall a gem, 'cap rvm:uninstall_gem GEM=my_gem'."
12
14
  rvm_task :uninstall_gem do
13
- run_rvm("gem uninstall --no-executables #{ENV['GEM']}", :with_ruby => rvm_ruby_string_evaluated)
15
+ run_rvm("gem uninstall --no-executables #{ENV['GEM']}",
16
+ :with_ruby => rvm_ruby_string_evaluated,
17
+ :subject_class => :gemsets)
14
18
  end
15
19
 
16
20
  end
@@ -2,13 +2,6 @@ require 'rvm/capistrano/base'
2
2
 
3
3
  rvm_with_capistrano do
4
4
 
5
- deferred_load do
6
-
7
- # Let users configure a path to export/import gemsets
8
- _cset(:rvm_gemset_path, "#{rvm_path}/gemsets")
9
-
10
- end
11
-
12
5
  namespace :rvm do
13
6
 
14
7
  desc <<-EOF
@@ -1,8 +1,8 @@
1
1
  require 'rvm/capistrano/base'
2
2
 
3
3
  rvm_with_capistrano do
4
- def run_silent_curl(command)
5
- run_without_rvm(<<-EOF.gsub(/[\s]+/, ' '))
4
+ def run_silent_curl(command, options={})
5
+ run_without_rvm(<<-EOF.gsub(/[\s]+/, ' '), options)
6
6
  __LAST_STATUS=0;
7
7
  export CURL_HOME="${TMPDIR:-${HOME}}/.rvm-curl-config.$$";
8
8
  mkdir ${CURL_HOME}/;
@@ -8,35 +8,54 @@ rvm_with_capistrano do
8
8
  end
9
9
 
10
10
  def rvm_if_sudo(options = {})
11
- case rvm_type
12
- when :root, :system
13
- if fetch(:use_sudo, true) == false && rvm_install_with_sudo == false
14
- explanation = <<-EXPLANATION
11
+ return '' unless need_root(options)
12
+ prohibited = sudo_prohibited(options)
13
+ return prohibited if prohibited # will cause a deferred error
14
+ return "#{sudo} "
15
+ end
16
+
17
+ def need_root(options = {})
18
+ return true if rvm_type == :root || rvm_type == :system
19
+ return false unless rvm_type == :mixed # must be user installation
20
+
21
+ # Finally deal with mixed installations. Whether we need sudo
22
+ # depends on what we're trying to do.
23
+ # If rvm_user config variable contains :gemsets (say), and we're
24
+ # operating on gemsets, then we don't need root. However, the
25
+ # most common use case for sudo is for installing rubies, so we
26
+ # default to that to keep the code simpler.
27
+ options[:subject_class] ||= :rubies
28
+
29
+ # rvm is installed system-wide in mixed installations
30
+ return true if options[:subject_class] == :rvm
31
+
32
+ return ! rvm_user.include?(options[:subject_class])
33
+ end
34
+
35
+ def sudo_prohibited(options = {})
36
+ return false if fetch(:use_sudo, true) || rvm_install_with_sudo
37
+
38
+ explanation = <<-EXPLANATION
15
39
  You can enable use_sudo within rvm for use only by this install operation by adding to deploy.rb:
16
40
 
17
41
  set :rvm_install_with_sudo, true
18
42
 
19
- EXPLANATION
20
- if options[:deferred]
21
- <<-DEFERRED_ERROR.gsub(/\n/, " ; ")
43
+ EXPLANATION
44
+
45
+ if options[:deferred]
46
+ <<-DEFERRED_ERROR.gsub(/\n/, " ; ")
22
47
  echo "
23
48
  Neither :use_sudo or :rvm_install_with_sudo was set and installation would ended up in using 'sudo'
24
49
  #{explanation}
25
50
  " >&2
26
51
  exit 1
27
- DEFERRED_ERROR
28
- else
29
- raise "
52
+ DEFERRED_ERROR
53
+ else
54
+ raise "
30
55
 
31
56
  :use_sudo is set to 'false' but sudo is needed to install rvm_type: #{rvm_type}.
32
57
  #{explanation}
33
58
  "
34
- end
35
- else
36
- "#{sudo} "
37
- end
38
- else
39
- ''
40
59
  end
41
60
  end
42
61
 
@@ -22,12 +22,30 @@ module Capistrano
22
22
  # shortcut to binary rvm #{command}
23
23
  # - use :with_rvm_group => true - to wrap it all in `with_rvm_group(...)` call
24
24
  # - use :with_ruby => 'with_ruby' - to extend to `.../bin/rvm #{with_ruby} do`
25
+ # - use :subject_class => :gemsets to indicate that the subject of the operation
26
+ # will be a gemset; valid values are any values which can be contained in
27
+ # the rvm_user config variable Array. This allows us to determine whether
28
+ # the subject is persisted system-wide or just per-user, and as a result
29
+ # whether sudo is required.
25
30
  def run_rvm(command, options={})
26
- cmd = "#{path_to_bin_rvm(options)} #{command}"
27
- cmd = with_rvm_group(cmd) if options[:with_rvm_group]
31
+ rvm_bin = path_to_bin_rvm(options)
32
+ cmd = "#{rvm_bin} #{command}"
33
+ cmd = with_rvm_group(cmd, options) if options[:with_rvm_group]
34
+ cmd = rvm_user_command(options) + cmd
28
35
  run_without_rvm(cmd)
29
36
  end
30
37
 
38
+ # If we're operating on something affected by the rvm user mode,
39
+ # we need to make sure that the server has the right rvm user mode.
40
+ # This returns a shell command to prepend to an existing command
41
+ # in order to achieve this.
42
+ def rvm_user_command(options={})
43
+ return '' unless rvm_type == :mixed && options[:subject_class]
44
+ rvm_user_args = rvm_user.empty? ? 'none' : rvm_user.map(&:to_s).join(' ')
45
+ rvm_bin = path_to_bin_rvm({ :with_ruby => true }.merge(options))
46
+ "#{rvm_bin} rvm user #{rvm_user_args} ; "
47
+ end
48
+
31
49
  # helper to find path to rvm binary
32
50
  def path_to_bin_rvm(options={})
33
51
  result = File.join(rvm_bin_path, "rvm")
@@ -4,13 +4,12 @@ require 'rvm/capistrano/helpers/quote_and_escape'
4
4
 
5
5
  rvm_with_capistrano do
6
6
 
7
- def with_rvm_group(command)
8
- case rvm_type
9
- when :root, :system
10
- <<-CODE
7
+ def with_rvm_group(command, options = {})
8
+ if need_root(options)
9
+ rvm_user_command + <<-CODE
11
10
  if id | grep ' groups=.*(rvm)' >/dev/null ;
12
11
  then #{command} ;
13
- else #{rvm_if_sudo(:deferred=>true)} sg rvm -c #{quote_and_escape(command)} ;
12
+ else #{rvm_if_sudo(options.merge(:deferred => true))} sg rvm -c #{quote_and_escape(command)} ;
14
13
  fi
15
14
  CODE
16
15
  else
@@ -40,7 +40,7 @@ ruby can not be installed when using :rvm_ruby_string => :#{ruby}
40
40
 
41
41
  "
42
42
  else
43
- command_install = ""
43
+ command_install = rvm_user_command(:subject_class => :rubies, :with_ruby=>ruby)
44
44
 
45
45
  autolibs_flag = fetch(:rvm_autolibs_flag, 2).to_s
46
46
  autolibs_flag_no_requirements = %w(
@@ -48,23 +48,21 @@ ruby can not be installed when using :rvm_ruby_string => :#{ruby}
48
48
  1 read read-only
49
49
  2 fail read-fail
50
50
  ).include?( autolibs_flag )
51
+ autolibs_flag = "1" unless autolibs_flag_no_requirements
51
52
 
52
53
  install_ruby_threads = fetch(:rvm_install_ruby_threads,nil).nil? ? '' : "-j #{rvm_install_ruby_threads}"
53
-
54
- if autolibs_flag_no_requirements
55
- command_install << with_rvm_group("#{path_to_bin_rvm} --autolibs=#{autolibs_flag} #{rvm_install_ruby} #{ruby} #{install_ruby_threads} #{rvm_install_ruby_params}")
56
- else
54
+ unless autolibs_flag_no_requirements
57
55
  command_install << "#{rvm_if_sudo} #{path_to_bin_rvm} --autolibs=#{autolibs_flag} requirements #{ruby}"
58
56
  command_install << "; "
59
- command_install << with_rvm_group("#{path_to_bin_rvm} --autolibs=1 #{rvm_install_ruby} #{ruby} #{install_ruby_threads} #{rvm_install_ruby_params}")
60
57
  end
58
+ command_install << with_rvm_group("#{path_to_bin_rvm} --autolibs=#{autolibs_flag} #{rvm_install_ruby} #{ruby} #{install_ruby_threads} #{rvm_install_ruby_params}", :subject_class => :rubies)
61
59
 
62
60
  if gemset
63
61
  command_install << "; "
64
- command_install << with_rvm_group("#{path_to_bin_rvm(:with_ruby=>ruby)} rvm gemset create #{gemset}")
62
+ command_install << with_rvm_group("#{path_to_bin_rvm(:with_ruby=>ruby)} rvm gemset create #{gemset}", :subject_class => :gemsets)
65
63
  end
66
64
 
67
- run_silent_curl command_install
65
+ run_silent_curl(command_install, :subject_class => :rubies)
68
66
  end
69
67
  end
70
68
 
@@ -28,7 +28,7 @@ rvm_with_capistrano do
28
28
  EOF
29
29
  rvm_task :install_rvm do
30
30
  command_fetch = "curl -L get.rvm.io"
31
- command_install = rvm_if_sudo
31
+ command_install = rvm_if_sudo(:subject_class => :rvm)
32
32
  command_install << "#{rvm_install_shell} -s #{rvm_install_type} --path #{rvm_path}"
33
33
  case rvm_type
34
34
  when :root, :system
@@ -1,5 +1,5 @@
1
1
  module RVM
2
2
  class Capistrano
3
- VERSION="1.4.4"
3
+ VERSION="1.5.0.rc1"
4
4
  end
5
5
  end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "rvm:create_gemset task" do
4
+ include_context "Capistrano::Configuration"
5
+
6
+ before {
7
+ @gemset = 'mygemset'
8
+ @configuration.set :rvm_ruby_string, '2.0.0@' + @gemset
9
+ @task = @configuration.find_task 'rvm:create_gemset'
10
+ }
11
+
12
+ it "should create a gemset in $HOME" do
13
+ @configuration.trigger :load
14
+ expected = "$HOME/.rvm/bin/rvm 2.0.0 do rvm gemset create #{@gemset}"
15
+ @task.namespace.should_receive(:run_without_rvm).with(expected)
16
+ @configuration.execute_task @task
17
+ end
18
+
19
+ it "should create a system-wide gemset" do
20
+ @configuration.set :rvm_type, :system
21
+ @configuration.trigger :load
22
+ expected = <<-EOSHELL.gsub(/^ /, '')
23
+ if id | grep ' groups=.*(rvm)' >/dev/null ;
24
+ then /usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create #{@gemset} ;
25
+ else sudo -p 'sudo password: ' sg rvm -c '/usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create #{@gemset}' ;
26
+ fi
27
+ EOSHELL
28
+ @task.namespace.should_receive(:run_without_rvm).with(expected)
29
+ @configuration.execute_task @task
30
+ end
31
+
32
+ it "should create a gemset in $HOME in mixed mode" do
33
+ @configuration.set :rvm_ruby_string, '2.0.0@' + @gemset
34
+ @configuration.set :rvm_type, :mixed
35
+ @configuration.set :rvm_user, [ :gemsets ]
36
+ @configuration.trigger :load
37
+ task = @configuration.find_task 'rvm:create_gemset'
38
+ expected = \
39
+ "/usr/local/rvm/bin/rvm 2.0.0 do rvm user gemsets ; " +
40
+ "/usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create #{@gemset}"
41
+ task.namespace.should_receive(:run_without_rvm).with(expected)
42
+ @configuration.execute_task task
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "rvm:create_gemset task" do
4
+ include_context "Capistrano::Configuration"
5
+
6
+ before {
7
+ @configuration.require 'rvm/capistrano/empty_gemset'
8
+ @gemset = 'mygemset'
9
+ @configuration.set :rvm_ruby_string, '2.0.0@' + @gemset
10
+ @task = @configuration.find_task 'rvm:empty_gemset'
11
+ }
12
+
13
+ it "should empty a gemset in $HOME" do
14
+ @configuration.trigger :load
15
+ expected = "$HOME/.rvm/bin/rvm 2.0.0 do rvm --force gemset empty #{@gemset}"
16
+ @task.namespace.should_receive(:run_without_rvm).with(expected)
17
+ @configuration.execute_task @task
18
+ end
19
+
20
+ it "should empty a system-wide gemset" do
21
+ @configuration.set :rvm_type, :system
22
+ @configuration.trigger :load
23
+ expected = <<-EOSHELL.gsub(/^ /, '')
24
+ if id | grep ' groups=.*(rvm)' >/dev/null ;
25
+ then /usr/local/rvm/bin/rvm 2.0.0 do rvm --force gemset empty #{@gemset} ;
26
+ else sudo -p 'sudo password: ' sg rvm -c '/usr/local/rvm/bin/rvm 2.0.0 do rvm --force gemset empty #{@gemset}' ;
27
+ fi
28
+ EOSHELL
29
+ @task.namespace.should_receive(:run_without_rvm).with(expected)
30
+ @configuration.execute_task @task
31
+ end
32
+ end
@@ -0,0 +1,124 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "rvm:install_ruby task" do
4
+ include_context "Capistrano::Configuration"
5
+
6
+ before {
7
+ @gemset = 'mygemset'
8
+ @configuration.set :rvm_ruby_string, '2.0.0@' + @gemset
9
+ @task = @configuration.find_task 'rvm:install_ruby'
10
+ }
11
+
12
+ it "should install a ruby in $HOME" do
13
+ @configuration.trigger :load
14
+ expected = ' ' + <<-EOSHELL.gsub(/^\s+/, '').gsub("\n", ' ')
15
+ __LAST_STATUS=0;
16
+ export CURL_HOME=\"${TMPDIR:-${HOME}}/.rvm-curl-config.$$\";
17
+ mkdir ${CURL_HOME}/;
18
+ {
19
+ [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc;
20
+ echo \"silent\";
21
+ echo \"show-error\";
22
+ } > $CURL_HOME/.curlrc;
23
+ $HOME/.rvm/bin/rvm --autolibs=2 install 2.0.0 ;
24
+ $HOME/.rvm/bin/rvm 2.0.0 do rvm gemset create mygemset || __LAST_STATUS=$?;
25
+ rm -rf $CURL_HOME;
26
+ exit ${__LAST_STATUS}
27
+ EOSHELL
28
+ @configuration.should_receive(:run_without_rvm) \
29
+ .with(expected, :subject_class => :rubies)
30
+ @configuration.execute_task @task
31
+ end
32
+
33
+ it "should install a ruby system-wide" do
34
+ @configuration.set :rvm_type, :system
35
+ @configuration.trigger :load
36
+ expected = ' ' + <<-EOSHELL.gsub(/^\s+/, '').gsub("\n", ' ')
37
+ __LAST_STATUS=0;
38
+ export CURL_HOME=\"${TMPDIR:-${HOME}}/.rvm-curl-config.$$\";
39
+ mkdir ${CURL_HOME}/;
40
+ {
41
+ [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc;
42
+ echo \"silent\";
43
+ echo \"show-error\";
44
+ } > $CURL_HOME/.curlrc;
45
+ if id | grep ' groups=.*(rvm)' >/dev/null ; then
46
+ /usr/local/rvm/bin/rvm --autolibs=2 install 2.0.0 ;
47
+ else
48
+ sudo -p 'sudo password: ' sg rvm -c '/usr/local/rvm/bin/rvm --autolibs=2 install 2.0.0 ' ;
49
+ fi ;
50
+ if id | grep ' groups=.*(rvm)' >/dev/null ; then
51
+ /usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create mygemset ;
52
+ else
53
+ sudo -p 'sudo password: ' sg rvm -c '/usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create mygemset' ;
54
+ fi || __LAST_STATUS=$?;
55
+ rm -rf $CURL_HOME;
56
+ exit ${__LAST_STATUS}
57
+ EOSHELL
58
+ @configuration.should_receive(:run_without_rvm) \
59
+ .with(expected, :subject_class => :rubies)
60
+ @configuration.execute_task @task
61
+ end
62
+
63
+ context "in mixed mode with user gemsets" do
64
+ before do
65
+ @configuration.set :rvm_type, :mixed
66
+ @configuration.set :rvm_user, [ :gemsets ]
67
+ @configuration.trigger :load
68
+ end
69
+
70
+ it "should install a ruby system-wide and create a user gemset" do
71
+ expected = ' ' + <<-EOSHELL.gsub(/^\s+/, '').gsub("\n", ' ')
72
+ __LAST_STATUS=0;
73
+ export CURL_HOME=\"${TMPDIR:-${HOME}}/.rvm-curl-config.$$\";
74
+ mkdir ${CURL_HOME}/;
75
+ {
76
+ [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc;
77
+ echo \"silent\";
78
+ echo \"show-error\";
79
+ } > $CURL_HOME/.curlrc;
80
+ /usr/local/rvm/bin/rvm 2.0.0 do rvm user gemsets ;
81
+ if id | grep ' groups=.*(rvm)' >/dev/null ; then
82
+ /usr/local/rvm/bin/rvm --autolibs=2 install 2.0.0 ;
83
+ else
84
+ sudo -p 'sudo password: ' sg rvm -c '/usr/local/rvm/bin/rvm --autolibs=2 install 2.0.0 ' ;
85
+ fi ;
86
+ /usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create mygemset || __LAST_STATUS=$?;
87
+ rm -rf $CURL_HOME;
88
+ exit ${__LAST_STATUS}
89
+ EOSHELL
90
+ @configuration.should_receive(:run_without_rvm) \
91
+ .with(expected, :subject_class => :rubies)
92
+ @configuration.execute_task @task
93
+ end
94
+ end
95
+
96
+ context "in mixed mode with user rubies and gemsets" do
97
+ before do
98
+ @configuration.set :rvm_type, :mixed
99
+ @configuration.set :rvm_user, [ :rubies, :gemsets ]
100
+ @configuration.trigger :load
101
+ end
102
+
103
+ it "should install a ruby and create a gemset in $HOME" do
104
+ expected = ' ' + <<-EOSHELL.gsub(/^\s+/, '').gsub("\n", ' ')
105
+ __LAST_STATUS=0;
106
+ export CURL_HOME=\"${TMPDIR:-${HOME}}/.rvm-curl-config.$$\";
107
+ mkdir ${CURL_HOME}/;
108
+ {
109
+ [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc;
110
+ echo \"silent\";
111
+ echo \"show-error\";
112
+ } > $CURL_HOME/.curlrc;
113
+ /usr/local/rvm/bin/rvm 2.0.0 do rvm user rubies gemsets ;
114
+ /usr/local/rvm/bin/rvm --autolibs=2 install 2.0.0 ;
115
+ /usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create mygemset || __LAST_STATUS=$?;
116
+ rm -rf $CURL_HOME;
117
+ exit ${__LAST_STATUS}
118
+ EOSHELL
119
+ @configuration.should_receive(:run_without_rvm) \
120
+ .with(expected, :subject_class => :rubies)
121
+ @configuration.execute_task @task
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,93 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "rvm paths" do
4
+ include_context "Capistrano::Configuration"
5
+
6
+ describe "default values" do
7
+ before { @configuration.trigger(:load) }
8
+
9
+ it "should return default system path" do
10
+ @configuration.fetch(:rvm_system_path).should == '/usr/local/rvm'
11
+ end
12
+
13
+ it "should return default user path" do
14
+ @configuration.fetch(:rvm_user_path).should == '$HOME/.rvm'
15
+ end
16
+
17
+ it "should return default installation mode" do
18
+ @configuration.fetch(:rvm_type).should == :user
19
+ end
20
+
21
+ it "should return default path" do
22
+ @configuration.fetch(:rvm_path).should == '$HOME/.rvm'
23
+ end
24
+
25
+ it "should return default bin path" do
26
+ @configuration.fetch(:rvm_bin_path).should == '$HOME/.rvm/bin'
27
+ end
28
+
29
+ it "should return default gemset path" do
30
+ @configuration.fetch(:rvm_gemset_path).should == '$HOME/.rvm/gemsets'
31
+ end
32
+ end
33
+
34
+ describe "system mode" do
35
+ before do
36
+ @configuration.set(:rvm_type, :system)
37
+ @configuration.trigger(:load)
38
+ end
39
+
40
+ it "should return default path" do
41
+ @configuration.fetch(:rvm_path).should == '/usr/local/rvm'
42
+ end
43
+
44
+ it "should return system bin path" do
45
+ @configuration.fetch(:rvm_bin_path).should == '/usr/local/rvm/bin'
46
+ end
47
+
48
+ it "should return system gemset path" do
49
+ @configuration.fetch(:rvm_gemset_path).should == '/usr/local/rvm/gemsets'
50
+ end
51
+ end
52
+
53
+ describe "invalid configuration values" do
54
+ context "in :mixed mode" do
55
+ before { @configuration.set(:rvm_type, :mixed) }
56
+
57
+ it "should abort if rvm_type is :mixed and rvm_user empty" do
58
+ expect { @configuration.trigger(:load) }.to \
59
+ abort_with_error(/When rvm_type is :mixed, you must also set rvm_user/)
60
+ end
61
+
62
+ it "should abort if rvm_user isn't an Array" do
63
+ @configuration.set(:rvm_user, "a string")
64
+ expect { @configuration.trigger(:load) }.to \
65
+ abort_with_error(/rvm_user must be an Array/)
66
+ end
67
+
68
+ it "should abort if rvm_user contains an invalid value" do
69
+ @configuration.set(:rvm_user, [ :invalid_value ])
70
+ expect { @configuration.trigger(:load) }.to \
71
+ abort_with_error(/Invalid value\(s\) in rvm_user: invalid_value/)
72
+ end
73
+
74
+ it "should abort if rvm_user mixes :none with other values" do
75
+ @configuration.set(:rvm_user, [ :none, :gemsets ])
76
+ expect { @configuration.trigger(:load) }.to \
77
+ abort_with_error(/rvm_user cannot mix :none with other values/)
78
+ end
79
+
80
+ it "should abort if rvm_user mixes :all with other values" do
81
+ @configuration.set(:rvm_user, [ :gemsets, :all ])
82
+ expect { @configuration.trigger(:load) }.to \
83
+ abort_with_error(/rvm_user cannot mix :all with other values/)
84
+ end
85
+ end
86
+
87
+ it "should abort if rvm_user is set and rvm_type isn't :mixed" do
88
+ @configuration.set(:rvm_user, [ :gemsets ])
89
+ expect { @configuration.trigger(:load) }.to \
90
+ abort_with_error(/rvm_user must not be set unless rvm_type is :mixed/)
91
+ end
92
+ end
93
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,3 @@
1
- require 'minitest'
2
- require 'minitest/spec'
1
+ # Requires supporting files with custom matchers and macros, etc,
2
+ # in ./support/ and its subdirectories.
3
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -0,0 +1,42 @@
1
+ require 'rspec/expectations'
2
+
3
+ RSpec::Matchers.define :abort_with_error do |message|
4
+ match do |block|
5
+ @block = block
6
+ with_fake_stderr do
7
+ @got_system_exit = false
8
+ begin
9
+ block.call
10
+ rescue SystemExit
11
+ @got_system_exit = true
12
+ @stderr = $stderr.string
13
+ message ? message === @stderr : true
14
+ else
15
+ false
16
+ end
17
+ end
18
+ end
19
+
20
+ description do
21
+ "blahhh"
22
+ end
23
+
24
+ failure_message_for_should do |actual|
25
+ if @got_system_exit
26
+ "expected STDERR to match " + \
27
+ ((message.is_a?(Regexp) ? "/%s/" : "'%s'") % message) + \
28
+ " but got:\n#{@stderr}"
29
+ else
30
+ "expected #{@block} to raise SystemExit"
31
+ end
32
+ end
33
+
34
+ # Fake STDERR and return a string written to it.
35
+ def with_fake_stderr
36
+ original_stderr = $stderr
37
+ $stderr = StringIO.new
38
+ yield
39
+ ensure
40
+ $stderr = original_stderr
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ require 'capistrano-spec'
2
+ require 'capistrano'
3
+
4
+ RSpec.configure do |config|
5
+ config.include Capistrano::Spec::Matchers
6
+ config.include Capistrano::Spec::Helpers
7
+ end
8
+
9
+ shared_context "Capistrano::Configuration" do
10
+ before do
11
+ @configuration = Capistrano::Configuration.new
12
+ $:.unshift File.dirname(__FILE__) + '/../../lib'
13
+ # @configuration.load_paths.unshift File.dirname(__FILE__) + '/../../lib'
14
+ Capistrano::Configuration.instance = @configuration
15
+
16
+ # define _cset etc. from capistrano
17
+ @configuration.load 'deploy'
18
+
19
+ # load rvm/capistrano/base etc.
20
+ @configuration.require 'rvm/capistrano'
21
+
22
+ @configuration.extend(Capistrano::Spec::ConfigurationExtension)
23
+ end
24
+ end
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rvm-capistrano
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease:
4
+ hash: 1792655073
5
+ prerelease: 6
6
6
  segments:
7
7
  - 1
8
- - 4
9
- - 4
10
- version: 1.4.4
8
+ - 5
9
+ - 0
10
+ - rc
11
+ - 1
12
+ version: 1.5.0.rc1
11
13
  platform: ruby
12
14
  authors:
13
15
  - Wayne E. Seguin
@@ -16,7 +18,7 @@ autorequire:
16
18
  bindir: bin
17
19
  cert_chain: []
18
20
 
19
- date: 2013-08-14 00:00:00 Z
21
+ date: 2013-08-18 00:00:00 Z
20
22
  dependencies:
21
23
  - !ruby/object:Gem::Dependency
22
24
  name: capistrano
@@ -49,7 +51,7 @@ dependencies:
49
51
  type: :development
50
52
  version_requirements: *id002
51
53
  - !ruby/object:Gem::Dependency
52
- name: minitest
54
+ name: rspec
53
55
  prerelease: false
54
56
  requirement: &id003 !ruby/object:Gem::Requirement
55
57
  none: false
@@ -62,6 +64,48 @@ dependencies:
62
64
  version: "0"
63
65
  type: :development
64
66
  version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: capistrano-spec
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: guard-rspec
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: guard-bundler
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ type: :development
108
+ version_requirements: *id006
65
109
  description: RVM / Capistrano Integration Gem
66
110
  email:
67
111
  - wayneeseguin@gmail.com
@@ -99,6 +143,12 @@ files:
99
143
  - lib/rvm/capistrano/helpers/rvm_methods.rb
100
144
  - lib/rvm/capistrano/helpers/with_rvm_group.rb
101
145
  - spec/spec_helper.rb
146
+ - spec/create_gemset_spec.rb
147
+ - spec/install_ruby_spec.rb
148
+ - spec/empty_gemset_spec.rb
149
+ - spec/support/capistrano.rb
150
+ - spec/support/abort_matcher.rb
151
+ - spec/rvm_paths_spec.rb
102
152
  homepage: https://github.com/wayneeseguin/rvm-capistrano
103
153
  licenses:
104
154
  - MIT
@@ -119,12 +169,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
169
  required_rubygems_version: !ruby/object:Gem::Requirement
120
170
  none: false
121
171
  requirements:
122
- - - ">="
172
+ - - ">"
123
173
  - !ruby/object:Gem::Version
124
- hash: 3
174
+ hash: 25
125
175
  segments:
126
- - 0
127
- version: "0"
176
+ - 1
177
+ - 3
178
+ - 1
179
+ version: 1.3.1
128
180
  requirements: []
129
181
 
130
182
  rubyforge_project:
@@ -134,3 +186,9 @@ specification_version: 3
134
186
  summary: RVM / Capistrano Integration Gem
135
187
  test_files:
136
188
  - spec/spec_helper.rb
189
+ - spec/create_gemset_spec.rb
190
+ - spec/install_ruby_spec.rb
191
+ - spec/empty_gemset_spec.rb
192
+ - spec/support/capistrano.rb
193
+ - spec/support/abort_matcher.rb
194
+ - spec/rvm_paths_spec.rb