Skip to content

Instantly share code, notes, and snippets.

...
let(:object) { Testing::Test.new }
let(:run_command) { stub(:stdout => 'Some string') }
let(:shellout) { stub(:run_command => run_command) }
it 'shells out' do
Mixlib::ShellOut.stub(:new).and_return(shellout)
expect(object.shellout).to eq('Some string')
end
...
@hartmantis
hartmantis / spec_helper.rb
Last active November 15, 2017 15:50
ChefSpec stubs for testing a recipe in isolation
require 'chefspec'
module SpecHelper
def global_stubs
# Don't worry about external cookbook dependencies
Chef::Cookbook::Metadata.any_instance.stub(:depends)
# Test each recipe in isolation, regardless of includes
@included_recipes = []
Chef::RunContext.any_instance.stub(:loaded_recipe?).and_return(false)