Sha256: e0342a395d5c4b6413be4b94a64c52b4b29c0bbf074668055b42865bd121f081

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

require 'pathname'
require 'spec_helper'

# action_root = Pathname.new(File.expand_path('../../../../lib/vagrant-rimu/actions', __FILE__))
# autoload :StopInstance, action_root.join('stop_instance')

describe VagrantPlugins::Rimu::Actions::StopInstance do
  let(:servers) { double('servers') }
  let(:shutdown) { double('shutdown') }
  let(:machine) { double('machine') }
  let(:state) { double('state') }
  let(:id) { '200' }

  let(:env) do
    {}.tap do |env|
      env[:ui] = double('ui').tap do |ui|
        ui.stub(:info).with(anything)
        ui.stub(:error).with(anything)
      end
      env[:rimu_api] = double('rimu_api').tap do |os|
        servers.stub(:shutdown) { shutdown }
        os.stub(:servers) { servers }
      end
      machine.stub(:id) { id }
      env[:machine] = machine
    end
  end

  let(:app) do
    double('app').tap do |app|
      app.stub(:call).with(anything)
    end
  end

  describe 'call' do
    context 'when server state id is not :stopped' do
      it 'stops the server' do
        state.stub(:id) { :running }
        env[:machine].stub(:state) { state }
        expect(env[:rimu_api].servers).to receive(:shutdown).with(id.to_i)
        expect(app).to receive(:call)
        @action = VagrantPlugins::Rimu::Actions::StopInstance.new(app, env)
        @action.call(env)
      end
    end
    context 'when server id is :stopped' do
      it 'does nothing' do
        state.stub(:id) { :stopped }
        env[:machine].stub(:state) { state }
        expect(env[:rimu_api].servers).to_not receive(:shutdown)
        expect(app).to receive(:call)
        @action = VagrantPlugins::Rimu::Actions::StopInstance.new(app, env)
        @action.call(env)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-rimu-0.0.4 spec/vagrant-rimu/actions/stop_instance_spec.rb
vagrant-rimu-0.0.3 spec/vagrant-rimu/actions/stop_instance_spec.rb
vagrant-rimu-0.0.2 spec/vagrant-rimu/actions/stop_instance_spec.rb
vagrant-rimu-0.0.1 spec/vagrant-rimu/actions/stop_instance_spec.rb