Skip to content

Using rspec autotest with chefspec

Tom Wilson edited this page Mar 11, 2015 · 3 revisions

rspec-autotest works well with chefspec. Changing a recipe spec, e.g. spec/recipes/my_recipe.rb runs the spec. However, changing the recipe itself doesn't automatically kick off the spec.

Assuming a single-cookbook repo with directory structure:

    - recipes
        my_recipe.rb
    - spec
        - recipes 
            my_recipe_spec.rb

add this to the .autotest file:

# fire recipe spec on recipe changes
Autotest.add_hook :initialize do |at|
  at.add_mapping(%r{\Arecipes/(.*)\.rb\z}) { |_, m|
    ["spec/recipes/#{m[1]}_spec.rb"]
  }
end

(No docs found for modifying the .autotest file or for add_hook method. Please add ref's if you know.)

Clone this wiki locally