Skip to content

Instantly share code, notes, and snippets.

@hartmantis
Last active November 15, 2017 15:50

Revisions

  1. hartmantis revised this gist May 3, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    require 'chefspec'

    module SpecHelpers
    module SpecHelper
    def global_stubs
    # Don't worry about external cookbook dependencies
    Chef::Cookbook::Metadata.any_instance.stub(:depends)
  2. hartmantis revised this gist May 2, 2013. 2 changed files with 17 additions and 11 deletions.
    11 changes: 0 additions & 11 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,11 +0,0 @@
    # 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)
    Chef::Recipe.any_instance.stub(:include_recipe) do |i|
    Chef::RunContext.any_instance.stub(:loaded_recipe?).with(i).and_return(true)
    @included_recipes << i
    end
    Chef::RunContext.any_instance.stub(:loaded_recipes).and_return(@included_recipes)
    17 changes: 17 additions & 0 deletions spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    require 'chefspec'

    module SpecHelpers
    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)
    Chef::Recipe.any_instance.stub(:include_recipe) do |i|
    Chef::RunContext.any_instance.stub(:loaded_recipe?).with(i).and_return(true)
    @included_recipes << i
    end
    Chef::RunContext.any_instance.stub(:loaded_recipes).and_return(@included_recipes)
    end
    end
  3. hartmantis created this gist May 2, 2013.
    11 changes: 11 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # 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)
    Chef::Recipe.any_instance.stub(:include_recipe) do |i|
    Chef::RunContext.any_instance.stub(:loaded_recipe?).with(i).and_return(true)
    @included_recipes << i
    end
    Chef::RunContext.any_instance.stub(:loaded_recipes).and_return(@included_recipes)