diff --git a/test/acceptance/base.rb b/test/acceptance/base.rb index b6119824d..edb33cd6f 100644 --- a/test/acceptance/base.rb +++ b/test/acceptance/base.rb @@ -8,7 +8,7 @@ require "log4r" $:.unshift File.expand_path("../", __FILE__) # Load in the supporting files for our tests -require "support/base_context" +require "support/shared/base_context" require "support/config" require "support/virtualbox" require "support/matchers/match_output" diff --git a/test/acceptance/ssh_test.rb b/test/acceptance/ssh_test.rb index 217e4c342..3d84356a7 100644 --- a/test/acceptance/ssh_test.rb +++ b/test/acceptance/ssh_test.rb @@ -1,21 +1,10 @@ require File.expand_path("../base", __FILE__) +require "support/shared/command_examples" describe "vagrant ssh" do include_context "acceptance" - - it "fails if no Vagrantfile is found" do - result = execute("vagrant", "ssh") - result.should_not be_success - result.stdout.should match_output(:no_vagrantfile) - end - - it "fails if the virtual machine is not created" do - assert_execute("vagrant", "init") - - result = execute("vagrant", "ssh") - result.should_not be_success - result.stdout.should match_output(:error_vm_must_be_created) - end + it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "ssh"] + it_behaves_like "a command that requires a virtual machine", ["vagrant", "ssh"] it "is able to SSH into a running virtual machine" do assert_execute("vagrant", "box", "add", "base", config.boxes["default"]) diff --git a/test/acceptance/support/base_context.rb b/test/acceptance/support/shared/base_context.rb similarity index 90% rename from test/acceptance/support/base_context.rb rename to test/acceptance/support/shared/base_context.rb index dd4f0db06..fa0f48ea4 100644 --- a/test/acceptance/support/base_context.rb +++ b/test/acceptance/support/shared/base_context.rb @@ -1,6 +1,6 @@ -require File.expand_path("../isolated_environment", __FILE__) -require File.expand_path("../output", __FILE__) -require File.expand_path("../virtualbox", __FILE__) +require "support/isolated_environment" +require "support/output" +require "support/virtualbox" shared_context "acceptance" do # Setup variables for the loggers of this test. These can be used to diff --git a/test/acceptance/support/shared/command_examples.rb b/test/acceptance/support/shared/command_examples.rb new file mode 100644 index 000000000..8cd911115 --- /dev/null +++ b/test/acceptance/support/shared/command_examples.rb @@ -0,0 +1,35 @@ +# This is a shared example that tests that a command requires a +# Vagrant environment to run properly. The exact command to run +# should be given as a parameter to the shared examples. +shared_examples "a command that requires a Vagrantfile" do |*args| + let(:command) do + raise ArgumentError, "A command must be set for the shared example." if args.empty? + args[0] + end + + it "fails if no Vagrantfile is found" do + result = execute(*command) + result.should_not be_success + result.stdout.should match_output(:no_vagrantfile) + end +end + +# This is a shared example that tests that the command requires a +# virtual machine to be created, and additionally to be in one of +# many states. +shared_examples "a command that requires a virtual machine" do |*args| + let(:command) do + raise ArgumentError, "A command must be set for the shared example." if args.empty? + args[0] + end + + it "fails if the virtual machine is not created" do + assert_execute("vagrant", "init") + + result = execute(*command) + result.should_not be_success + result.stdout.should match_output(:error_vm_must_be_created) + end + + # TODO: Check for specific VM states: running, stopped, etc. +end diff --git a/test/acceptance/up_basic_test.rb b/test/acceptance/up_basic_test.rb index 0d7ca501b..7bb9c4bcf 100644 --- a/test/acceptance/up_basic_test.rb +++ b/test/acceptance/up_basic_test.rb @@ -1,13 +1,9 @@ require File.expand_path("../base", __FILE__) +require "support/shared/command_examples" describe "vagrant up", "basics" do include_context "acceptance" - - it "fails if not Vagrantfile is found" do - result = execute("vagrant", "up") - result.should_not be_success - result.stdout.should match_output(:no_vagrantfile) - end + it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "up"] it "brings up a running virtual machine" do assert_execute("vagrant", "box", "add", "base", config.boxes["default"])