Skip to content

Instantly share code, notes, and snippets.

@acrmp
Created October 31, 2012 02:42
Show Gist options
  • Save acrmp/3984500 to your computer and use it in GitHub Desktop.
Save acrmp/3984500 to your computer and use it in GitHub Desktop.
retr0h
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment