Shared contexts for Vagrant command similarities
This commit is contained in:
parent
8787c4b876
commit
7a07a78bf1
|
@ -8,7 +8,7 @@ require "log4r"
|
||||||
$:.unshift File.expand_path("../", __FILE__)
|
$:.unshift File.expand_path("../", __FILE__)
|
||||||
|
|
||||||
# Load in the supporting files for our tests
|
# Load in the supporting files for our tests
|
||||||
require "support/base_context"
|
require "support/shared/base_context"
|
||||||
require "support/config"
|
require "support/config"
|
||||||
require "support/virtualbox"
|
require "support/virtualbox"
|
||||||
require "support/matchers/match_output"
|
require "support/matchers/match_output"
|
||||||
|
|
|
@ -1,21 +1,10 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
require File.expand_path("../base", __FILE__)
|
||||||
|
require "support/shared/command_examples"
|
||||||
|
|
||||||
describe "vagrant ssh" do
|
describe "vagrant ssh" do
|
||||||
include_context "acceptance"
|
include_context "acceptance"
|
||||||
|
it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "ssh"]
|
||||||
it "fails if no Vagrantfile is found" do
|
it_behaves_like "a command that requires a virtual machine", ["vagrant", "ssh"]
|
||||||
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 "is able to SSH into a running virtual machine" do
|
it "is able to SSH into a running virtual machine" do
|
||||||
assert_execute("vagrant", "box", "add", "base", config.boxes["default"])
|
assert_execute("vagrant", "box", "add", "base", config.boxes["default"])
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require File.expand_path("../isolated_environment", __FILE__)
|
require "support/isolated_environment"
|
||||||
require File.expand_path("../output", __FILE__)
|
require "support/output"
|
||||||
require File.expand_path("../virtualbox", __FILE__)
|
require "support/virtualbox"
|
||||||
|
|
||||||
shared_context "acceptance" do
|
shared_context "acceptance" do
|
||||||
# Setup variables for the loggers of this test. These can be used to
|
# Setup variables for the loggers of this test. These can be used to
|
|
@ -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
|
|
@ -1,13 +1,9 @@
|
||||||
require File.expand_path("../base", __FILE__)
|
require File.expand_path("../base", __FILE__)
|
||||||
|
require "support/shared/command_examples"
|
||||||
|
|
||||||
describe "vagrant up", "basics" do
|
describe "vagrant up", "basics" do
|
||||||
include_context "acceptance"
|
include_context "acceptance"
|
||||||
|
it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "up"]
|
||||||
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 "brings up a running virtual machine" do
|
it "brings up a running virtual machine" do
|
||||||
assert_execute("vagrant", "box", "add", "base", config.boxes["default"])
|
assert_execute("vagrant", "box", "add", "base", config.boxes["default"])
|
||||||
|
|
Loading…
Reference in New Issue