vaguerent/test/unit/vagrant/batch_action_test.rb
Fabio Rehm 54656151cf Convert specs to RSpec 2.14.8 syntax with Transpec
This conversion is done by Transpec 1.10.2 with the following command:
    transpec test/unit/

* 507 conversions
    from: obj.should
      to: expect(obj).to

* 394 conversions
    from: == expected
      to: eq(expected)

* 260 conversions
    from: obj.should_receive(:message)
      to: expect(obj).to receive(:message)

* 85 conversions
    from: obj.stub(:message)
      to: allow(obj).to receive(:message)

* 25 conversions
    from: its(:attr) { }
      to: describe '#attr' do subject { super().attr }; it { } end

* 19 conversions
    from: obj.should_not
      to: expect(obj).not_to

* 7 conversions
    from: obj.should_not_receive(:message)
      to: expect(obj).not_to receive(:message)

* 3 conversions
    from: Klass.any_instance.should_receive(:message)
      to: expect_any_instance_of(Klass).to receive(:message)
2014-03-14 12:02:07 -03:00

58 lines
1.5 KiB
Ruby

require 'thread'
require 'timeout'
require File.expand_path("../../base", __FILE__)
describe Vagrant::BatchAction do
let(:called_actions) { [] }
let!(:lock) { Mutex.new }
let(:provider_name) { "test" }
let(:provider_options) { {} }
def new_machine(options)
double("machine").tap do |m|
m.stub(:provider_name => provider_name)
m.stub(:provider_options => options)
allow(m).to receive(:action) do |action, opts|
lock.synchronize do
called_actions << [m, action, opts]
end
end
end
end
describe "#run" do
let(:machine) { new_machine(provider_options) }
let(:machine2) { new_machine(provider_options) }
it "should run the actions on the machines in order" do
subject.action(machine, "up")
subject.action(machine2, "destroy")
subject.run
expect(called_actions.include?([machine, "up", nil])).to be
expect(called_actions.include?([machine2, "destroy", nil])).to be
end
it "should handle forks gracefully", :skip_windows do
# Doesn't need to be tested on Windows since Windows doesn't
# support fork(1)
allow(machine).to receive(:action) do |action, opts|
pid = fork
if !pid
# Child process
exit
end
# Parent process, wait for the child to exit
Timeout.timeout(1) do
Process.waitpid(pid)
end
end
subject.action(machine, "up")
subject.run
end
end
end