Skip to content

Instantly share code, notes, and snippets.

@jperry
Created March 28, 2012 19:33
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 jperry/2229720 to your computer and use it in GitHub Desktop.
Save jperry/2229720 to your computer and use it in GitHub Desktop.
Chefspec example
spec_helper.rb
Rspec.configure do |config|
def converge(recipe_name)
chef_run = ChefSpec::ChefRunner.new(:cookbook_path => File.dirname(__FILE__))
chef_run.coverge recipe_name
chef_run
end
end
default.rb (attribute file)
default[:tmpreaper][:time] = "7d"
if search(:node, "role:rails_utility").length > 0
default[:tmpreaper][:time] = "3d"
end
default_spec.rb
describe 'tmpreaper::default' do
before(:all) do
@chef_run = converge "tmpreaper::default"
end
describe "attributes" do
it "should set the correct values by default" do
#pending("Waiting for response back from gem author why mocks aren't working")
@chef_run.node.tmpreaper[:time].should == "7d"
end
it "should set the correct values when there are nodes with the rails_utility role" do
@chef_run.node.tmpreaper[:time].should == "3d"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment