diff --git a/.travis.yml b/.travis.yml index 5e7d8cc3..989b6ef5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,3 @@ rvm: - rbx script: bundle exec rake spec cache: bundler -bundler_args: --without cucumber diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e0af8c0..5709865d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ https://github.com/capistrano/capistrano/compare/v3.2.1...HEAD * Minor Changes * Added tests for after/before hooks features (@juanibiapina, @miry) * Improved the output of `cap --help`. (@mbrictson) + * Cucumber suite now runs on the latest version of Vagrant (@tpett) ## `3.2.1` diff --git a/Gemfile b/Gemfile index 8b274d5d..297d2438 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,6 @@ source 'https://rubygems.org' gemspec group :cucumber do - gem 'kuroko' gem 'cucumber' end diff --git a/README.md b/README.md index 17c63208..80fec1cc 100644 --- a/README.md +++ b/README.md @@ -274,6 +274,27 @@ connections behind the scenes in Capistrano. Depending on how deep you dig, you might run into interfaces that come directly from SSHKit (the configuration is a good example). +## Testing + +Capistrano has two test suites: an RSpec suite and a Cucumber suite. The +RSpec suite handles quick feedback unit specs. The Cucumber features are +an integration suite that uses Vagrant to deploy to a real virtual +server. In order to run the Cucumber suite you will need to install +[Vagrant](http://www.vagrantup.com/) and Vagrant supported +virtualization software like +[VirtualBox](https://www.virtualbox.org/wiki/Downloads). + +``` +# To run the RSpec suite +$ rake spec + +# To run the Cucumber suite +$ rake features + +# To run the Cucumber suite and leave the VM running (faster for subsequent runs) +$ rake features KEEP_RUNNING=1 +``` + ## License MIT License (MIT) diff --git a/Rakefile b/Rakefile index 50917584..fc943b19 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,9 @@ require "bundler/gem_tasks" +require "cucumber/rake/task" +require "rspec/core/rake_task" task :default => :spec -require 'rspec/core/rake_task' RSpec::Core::RakeTask.new + +Cucumber::Rake::Task.new(:features) + diff --git a/features/step_definitions/assertions.rb b/features/step_definitions/assertions.rb index 36a0d3cd..b16ba2e5 100644 --- a/features/step_definitions/assertions.rb +++ b/features/step_definitions/assertions.rb @@ -100,7 +100,8 @@ end Then(/^the failure task will not run$/) do failed = TestApp.shared_path.join('failed') - !run_vagrant_command(test_file_exists(failed)) + expect { run_vagrant_command(test_file_exists(failed)) } + .to raise_error(VagrantHelpers::VagrantSSHCommandError) end When(/^an error is raised$/) do diff --git a/features/support/env.rb b/features/support/env.rb index 3aed709c..853b6f19 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,12 +1,11 @@ -require 'kuroko' +PROJECT_ROOT = File.expand_path('../../../', __FILE__) +VAGRANT_ROOT = File.join(PROJECT_ROOT, 'spec/support') +VAGRANT_BIN = ENV['VAGRANT_BIN'] || "vagrant" -project_root = File.expand_path('../../../', __FILE__) -vagrant_root = File.join(project_root, 'spec/support') - -Kuroko.configure do |config| - config.vagrant_root = 'spec/support' +at_exit do + if ENV['KEEP_RUNNING'] + VagrantHelpers.run_vagrant_command("rm -rf /home/vagrant/var") + end end -puts vagrant_root.inspect - require_relative '../../spec/support/test_app' diff --git a/features/support/remote_command_helpers.rb b/features/support/remote_command_helpers.rb index 7c045608..9b5232bb 100644 --- a/features/support/remote_command_helpers.rb +++ b/features/support/remote_command_helpers.rb @@ -1,5 +1,4 @@ module RemoteCommandHelpers - def test_dir_exists(path) exists?('d', path) end @@ -13,11 +12,11 @@ module RemoteCommandHelpers end def exists?(type, path) - %{[ -#{type} "#{path}" ] && echo "#{path} exists." || echo "Error: #{path} does not exist."} + %{[ -#{type} "#{path}" ]} end def safely_remove_file(path) - run_vagrant_command("rm #{test_file}") rescue Vagrant::Errors::VagrantError + run_vagrant_command("rm #{test_file}") rescue VagrantHelpers::VagrantSSHCommandError end end diff --git a/features/support/vagrant_helpers.rb b/features/support/vagrant_helpers.rb new file mode 100644 index 00000000..1a1822a8 --- /dev/null +++ b/features/support/vagrant_helpers.rb @@ -0,0 +1,35 @@ +module VagrantHelpers + extend self + + class VagrantSSHCommandError < RuntimeError; end + + at_exit do + if ENV['KEEP_RUNNING'] + puts "Vagrant vm will be left up because KEEP_RUNNING is set." + puts "Rerun without KEEP_RUNNING set to cleanup the vm." + else + vagrant_cli_command("destroy -f") + end + end + + def vagrant_cli_command(command) + puts "[vagrant] #{command}" + Dir.chdir(VAGRANT_ROOT) do + `#{VAGRANT_BIN} #{command} 2>&1`.split("\n").each do |line| + puts "[vagrant] #{line}" + end + end + $? + end + + def run_vagrant_command(command) + if (status = vagrant_cli_command("ssh -c #{command.inspect}")).success? + true + else + fail VagrantSSHCommandError, status + end + end + +end + +World(VagrantHelpers) diff --git a/spec/support/test_app.rb b/spec/support/test_app.rb index e6aa848a..36d007ad 100644 --- a/spec/support/test_app.rb +++ b/spec/support/test_app.rb @@ -1,4 +1,6 @@ require 'fileutils' +require 'pathname' + module TestApp extend self