Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Merge pull request #18 from miroswan/fix/handle-no-machines
Browse files Browse the repository at this point in the history
Fix/handle no machines
  • Loading branch information
miroswan authored Aug 13, 2016
2 parents c52de80 + bae56eb commit d1b66a9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
15 changes: 11 additions & 4 deletions lib/vagrant_spec/test_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ def initialize(env)
# This will fail if any of the tests fail, but it will allow all tests to
# run
def run
print_banner
@test_plan.each do |plan|
found_nodes = nodes(plan)
if found_nodes
found_nodes.each { |node| execute_plan_tests(node, plan) }
end
end
exit @ret_code
end

def print_banner
@env.ui.info('*******************************************************')
@env.ui.info('***************** ServerSpec Test Run *****************')
@env.ui.info('*******************************************************')
@env.ui.info('')
@test_plan.each do |plan|
nodes(plan).each { |node| execute_plan_tests(node, plan) }
end
exit @ret_code
end

# Return array of active Vagrant machines
Expand Down
29 changes: 15 additions & 14 deletions spec/unit/vagrant_spec_test/test_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
describe VagrantSpec::TestPlan do
include RSpec::Support::InSubProcess
include_context 'unit'

##############################################################################
# mocks

include_examples 'shared_mocks'

let(:mock_plan) do
Expand All @@ -40,9 +36,6 @@

let(:mock_ssh_backend) { double(Specinfra::Backend::Ssh) }

##############################################################################
# Stubs

before do
allow_any_instance_of(VagrantSpec::MachineFinder)
.to receive(:match_nodes) { [double(Vagrant::Machine)] }
Expand All @@ -63,6 +56,11 @@

subject { VagrantSpec::TestPlan.new(iso_env) }

it '#print_banner prints the testing initialization banner' do
expect(mock_ui).to receive(:info)
subject.print_banner
end

context 'when passing a Regexp object' do
it '#nodes calls match_nodes on a machine_finder instance' do
expect(subject.m_finder).to receive(:match_nodes)
Expand Down Expand Up @@ -93,13 +91,6 @@
end
end

##############################################################################
# Testing #execute_plan_tests
#
# These tests must be executed in a sub process because execute_plan_tests
# executes clear_examples. clear_examples modifies global state, so we must
# contain it.

def execute_plan_tests_proc
proc do
allow(subject).to receive(:close_ssh)
Expand Down Expand Up @@ -129,4 +120,14 @@ def execute_plan_tests_proc
expect(subject).to receive(:configure_serverspec)
end
end

context 'when nodes returns nil' do
it '#run does not fail with NoMethodError' do
allow(subject).to receive(:execute_plan_tests)
allow(subject).to receive(:exit)
allow(subject).to receive(:nodes) { nil }

expect { subject.run }.not_to raise_error
end
end
end

0 comments on commit d1b66a9

Please sign in to comment.