Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version manager tests #693

Merged
merged 4 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@

$stdout, $stderr = original_stdout, original_stderr
end

config.around(:all) do |example|
begin
example.run
rescue SystemExit => e
raise "Unhandled system exit (you're probably missing a raise_error(SystemExit) matcher somewhere)"
end
end
end
9 changes: 0 additions & 9 deletions spec/support/outputs/chruby.txt

This file was deleted.

7 changes: 7 additions & 0 deletions spec/support/outputs/chruby_with_env.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
echo "-----> chruby to version: \\"123\\""
if \[\[ ! -s "/etc/profile\.d/chruby\.sh" \]\]; then
echo "! chruby\.sh init file not found"
exit 1
fi
source /etc/profile\.d/chruby\.sh
chruby "123" \|\| exit 1
2 changes: 2 additions & 0 deletions spec/support/outputs/chruby_without_env.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Task 'chruby' needs a Ruby version as an argument\.
Example: invoke :chruby, 'ruby-2.4'
10 changes: 9 additions & 1 deletion spec/support/outputs/rbenv_load.txt
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
echo\ "\-\-\-\-\->\ Loading\ rbenv"\nexport\ RBENV_ROOT="\$HOME/\.rbenv"\nexport\ PATH="\$HOME/\.rbenv/bin:\$PATH"\s*if\ !\ which\ rbenv\ >/dev/null;\ then\s*echo\ "!\ rbenv\ not\ found"\s*echo\ "!\ If\ rbenv\ is\ installed,\ check\ your\ :rbenv_path\ setting\."\s*exit\ 1\s*fi\s*eval\ "\$\(rbenv\ init\ \-\)"
echo "-----> Loading rbenv"
export RBENV_ROOT="\$HOME/\.rbenv"
export PATH="\$HOME/\.rbenv/bin:\$PATH"
if ! which rbenv >/dev/null; then
echo "! rbenv not found"
echo "! If rbenv is installed, check your :rbenv_path setting\."
exit 1
fi
eval "\$\(rbenv init -\)"
1 change: 0 additions & 1 deletion spec/support/outputs/rvm_use.txt

This file was deleted.

8 changes: 8 additions & 0 deletions spec/support/outputs/rvm_use_with_env.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
echo "-----> Using RVM environment \\"3\.0\.0\\""
if \[\[ ! -s "\$HOME/\.rvm/scripts/rvm" \]\]; then
echo "! Ruby Version Manager not found"
echo "! If RVM is installed, check your :rvm_use_path setting\."
exit 1
fi
source \$HOME/\.rvm/scripts/rvm
rvm use "3\.0\.0" --create
2 changes: 2 additions & 0 deletions spec/support/outputs/rvm_use_without_env.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Task 'rvm:use' needs an RVM environment name as an argument\.
Example: invoke :'rvm:use', 'ruby-1\.9\.2@default'
8 changes: 8 additions & 0 deletions spec/support/outputs/rvm_wrapper_with_arguments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
echo "-----> creating RVM wrapper "myapp_unicorn" using \\"3\.0\.0\\""
if \[\[ ! -s "\$HOME/\.rvm/scripts/rvm" \]\]; then
echo "! Ruby Version Manager not found"
echo "! If RVM is installed, check your :rvm_use_path setting\."
exit 1
fi
source \$HOME/\.rvm/scripts/rvm
rvm wrapper 3\.0\.0 myapp unicorn \|\| exit 1
2 changes: 2 additions & 0 deletions spec/support/outputs/rvm_wrapper_without_arguments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Task 'rvm:wrapper' needs an RVM environment name, a wrapper name and the binary name as arguments
Example: invoke :'rvm:wrapper', 'ruby-1\.9\.2@myapp,myapp,unicorn_rails'
15 changes: 0 additions & 15 deletions spec/support/outputs/ry.txt

This file was deleted.

13 changes: 13 additions & 0 deletions spec/support/outputs/ry_with_env.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
echo "-----> ry to version: \\\"3\.0\.0\\\""
echo "-----> Loading ry"
if \[\[ ! -e "\$HOME/\.local/bin" \]\]; then
echo "! ry not found"
echo "! If ry is installed, check your :ry_path setting."
exit 1
fi
export PATH="\$HOME/\.local/bin:\$PATH"
eval "\$\(ry setup\)"
RY_RUBY="3\.0\.0"
if \[ -n "\$RY_RUBY" \]; then
ry use \$RY_RUBY \|\| exit 1
fi
13 changes: 13 additions & 0 deletions spec/support/outputs/ry_without_env.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
echo "-----> ry to version: \\"\*\*not specified\*\*\\""
echo "-----> Loading ry"
if \[\[ ! -e "\$HOME/\.local/bin" \]\]; then
echo "! ry not found"
echo "! If ry is installed, check your :ry_path setting."
exit 1
fi
export PATH="\$HOME/\.local/bin:\$PATH"
eval "\$\(ry setup\)"
RY_RUBY=""
if \[ -n "\$RY_RUBY" \]; then
ry use \$RY_RUBY \|\| exit 1
fi
4 changes: 2 additions & 2 deletions spec/support/rake_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def self.included(klass)
end
end

def invoke_all(args = nil)
subject.invoke(args)
def invoke_all(*args)
subject.invoke(*args)
run_commands.invoke
end

Expand Down
23 changes: 23 additions & 0 deletions spec/tasks/chruby_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

RSpec.describe 'chruby', type: :rake do
describe 'chruby' do
subject { rake['chruby'] }

context 'without an argument' do
it 'exits with an error message' do
expect do
invoke_all
end.to raise_error(SystemExit).and output(output_file('chruby_without_env')).to_stdout
end
end

context 'with an argument' do
it 'sets ruby version' do
expect do
invoke_all('123')
end.to output(output_file('chruby_with_env')).to_stdout
end
end
end
end
9 changes: 9 additions & 0 deletions spec/tasks/rbenv_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

RSpec.describe 'rbenv', type: :rake do
describe 'rbenv:load' do
it 'loads rbenv' do
expect { invoke_all }.to output(output_file('rbenv_load')).to_stdout
end
end
end
33 changes: 0 additions & 33 deletions spec/tasks/ruby_managers_spec.rb

This file was deleted.

45 changes: 45 additions & 0 deletions spec/tasks/rvm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'spec_helper'

RSpec.describe 'rvm', type: :rake do
describe 'rvm:use' do
subject { rake['rvm:use'] }

context 'without an argument' do
it 'exits with an error message' do
expect do
invoke_all
end.to raise_error(SystemExit)
.and output(output_file('rvm_use_without_env')).to_stdout
end
end

context 'with an argument' do
it 'sets ruby version' do
expect do
invoke_all('3.0.0')
end.to output(output_file('rvm_use_with_env')).to_stdout
end
end
end

describe 'rvm:wrapper' do
subject { rake['rvm:wrapper'] }

context 'without all arguments' do
it 'exits with an error message' do
expect do
invoke_all('ruby-3.0.0')
end.to raise_error(SystemExit)
.and output(output_file('rvm_wrapper_without_arguments')).to_stdout
end
end

context 'with all arguments' do
it 'calls rvm wrapper' do
expect do
invoke_all('3.0.0', 'myapp', 'unicorn')
end.to output(output_file('rvm_wrapper_with_arguments')).to_stdout
end
end
end
end
37 changes: 37 additions & 0 deletions spec/tasks/ry_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'spec_helper'

RSpec.describe 'ry', type: :rake do
describe 'ry' do
subject { rake['ry'] }

let(:default_version_warning) { /Task 'ry' without argument will use default Ruby version\./ }

context 'without an argument' do
it 'prints a warning' do
expect do
invoke_all
end.to output(default_version_warning).to_stdout
end

it 'sets ruby version' do
expect do
invoke_all
end.to output(output_file('ry_without_env')).to_stdout
end
end

context 'with an argument' do
it "doesn't print a warning" do
expect do
invoke_all('3.0.0')
end.not_to output(default_version_warning).to_stdout
end
end

it 'sets ruby version' do
expect do
invoke_all('3.0.0')
end.to output(output_file('ry_with_env')).to_stdout
end
end
end
2 changes: 1 addition & 1 deletion tasks/mina/rvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

task :'rvm:wrapper', :env, :name, :bin do |_, args|
unless args[:env] && args[:name] && args[:bin]
puts "Task 'rvm:wrapper' needs an RVM environment name, an wrapper name and the binary name as arguments"
puts "Task 'rvm:wrapper' needs an RVM environment name, a wrapper name and the binary name as arguments"
puts "Example: invoke :'rvm:wrapper', 'ruby-1.9.2@myapp,myapp,unicorn_rails'"
exit 1
end
Expand Down