Skip to content

Instantly share code, notes, and snippets.

@acrmp
Created October 31, 2012 02:42
Show Gist options
  • Select an option

  • Save acrmp/3984500 to your computer and use it in GitHub Desktop.

Select an option

Save acrmp/3984500 to your computer and use it in GitHub Desktop.

Revisions

  1. Andrew Crump created this gist Oct 31, 2012.
    36 changes: 36 additions & 0 deletions reboot_spec.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    require "chefspec"
    require 'mixlib/shellout'
    require "ostruct"
    require ::File.join ::File.dirname(__FILE__), "..", "files", "default", "reboot"

    describe Reboot do
    ::Chef::ShellOut.class_eval do
    def run_command
    true
    end
    end
    let(:handler){ Reboot.new }
    let(:node){ChefSpec::ChefRunner.new.converge('reboot-handler::default').node}
    let(:run_status){ Chef::RunStatus.new(node, Chef::EventDispatch::Dispatcher.new) }

    it "should not reboot if the run failed" do
    run_status.exception = Exception.new
    handler.run_report_unsafe(run_status).should_not be
    end

    it "should not reboot if the node does not have the reboot role" do
    handler.run_report_unsafe(run_status).should_not be
    end

    it "should not reboot if the node has the role but the flag is not set" do
    node.roles << node['reboot-handler']['enabled_role']
    handler.run_report_unsafe(run_status).should_not be
    end

    it "should reboot if the role and flag are set" do
    node.roles << node['reboot-handler']['enabled_role']
    node.run_state['reboot'] = true
    handler.run_report_unsafe(run_status).should be
    end

    end