sethvargo/chefspec — pull request #317 by lynx44 (2014-01-18 06:21:28+00:00)
Title: Added automatic resource matcher

Not sure if this is something that has been avoided by design, but I just recently started testing with ChefSpec and I was surprised that this wasn't built in functionality. From the sound of issue https://github.com/sethvargo/chefspec/issues/241, it may be a thought, but never implemented.

I ended up adding an automatic resource matcher to handle LWRPs that are defined in third party cookbooks to my own project, so I've created this pull request in case there's interest in including it in the master branch. I haven't tested it with Berkshelf or Librarian, but assuming that they use the same Chef::Config[:cookbook_path] variable, it should work. If I'm wrong, I'd be willing to test it out if that would be necessary for inclusion.

To use it, the file simply needs to be included in the spec:

require 'chefspec'
require 'chefspec/lib/chefspec/mixins/automatic_resource_matcher'

describe 'my_cookbook::default' do
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }

it 'passes syntax checks' do
expect(chef_run).to run_my_cookbook_my_lwrp('test')
end
end