Skip to content

Instantly share code, notes, and snippets.

@ifosch
Created July 9, 2015 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ifosch/af0cf9c5b0b4b225f6a4 to your computer and use it in GitHub Desktop.
Save ifosch/af0cf9c5b0b4b225f6a4 to your computer and use it in GitHub Desktop.
Chef library helper test and error
# spec/opsworks_spec.rb
require_relative '../spec_helper.rb'
describe OpsWorks::Helper do
describe '#local?' do
let(:recipe) { Object.new.extend(OpsWorks::Helper) }
before do
@run = ChefSpec::Runner.new.converge 'common::default'
end
context 'without opsworks' do
it 'returns true' do
expect(recipe.local?).to be true
end
end
end
end
# libraries/opsworks.rb
module OpsWorks
module Helper
def local?
node.key? 'opsworks'
end
end
end
# Test output
1) OpsWorks::Helper#local? without opsworks returns true
Failure/Error: expect(recipe.local?).to be true
NameError:
undefined local variable or method `node' for #<Object:0x007ff99a8689b8>
# ./common/libraries/opsworks.rb:4:in `local?'
# ./common/spec/libraries/opsworks_spec.rb:13:in `block (4 levels) in <top (required)>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment