RiotGames/berkshelf — pull request #401 by charlesjohnson (2013-03-07 21:38:09+00:00)
Title: Added feature to automatically generate cookbooks with built-in support ...

...for chef-minitest. Tests included.

When cookbook command is given --chef_minitest option, Berkshelf will now generate empty chef-minitest files and include the minitest-handler in the run_list of the Vagrantfile.

:warning: test failure in the spec tests. Cucumber tests all pass. Problem is in spec/unit/berkshelf/init_generator_spec.rb, lines 161 - 200. Because the feature automatically includes a cookbook in the Berksfile, the spec tests attempt to contact the Chef Server API. I've mocked the API but I'm pretty sure I'm not mocking it API appropriately, causing a null at community_rest.rb:115:in `versions'.

I'm not sure what the correct mock should look like. Guidance would be appreciated.

Stack below:

```
$ rspec spec/unit/berkshelf/init_generator_spec.rb
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}
..........

Finished in 0.23886 seconds
10 examples, 0 failures
VN-GO-4:berkshelf charlesjohnson$ rspec spec/unit/berkshelf/init_generator_spec.rb
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}
..........F

Failures:

1) Berkshelf::InitGenerator with the chef_minitest option true
Failure/Error: subject.new([target], chef_minitest: true).invoke_all
WebMock::NetConnectNotAllowedError:
Real HTTP connections are disabled. Unregistered request: GET http://cookbooks.opscode.com/api/v1/cookbooks/minitest-handler with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.8.6'}

You can stub this request with the following snippet:

stub_request(:get, "http://cookbooks.opscode.com/api/v1/cookbooks/minitest-handler").
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.8.6'}).
to_return(:status => 200, :body => "", :headers => {})

============================================================
# ./lib/berkshelf/community_rest.rb:115:in `versions'
# ./lib/berkshelf/community_rest.rb:134:in `satisfy'
# ./lib/berkshelf/locations/site_location.rb:62:in `target_version'
# ./lib/berkshelf/locations/site_location.rb:36:in `download'
# ./lib/berkshelf/downloader.rb:110:in `block in search_locations'
# ./lib/berkshelf/downloader.rb:103:in `each'
# ./lib/berkshelf/downloader.rb:103:in `search_locations'
# ./lib/berkshelf/downloader.rb:79:in `download'
# ./lib/berkshelf/resolver.rb:129:in `install_source'
# ./lib/berkshelf/resolver.rb:49:in `add_source'
# ./lib/berkshelf/resolver.rb:22:in `block in initialize'
# ./lib/berkshelf/resolver.rb:21:in `each'
# ./lib/berkshelf/resolver.rb:21:in `initialize'
# ./lib/berkshelf/berksfile.rb:362:in `new'
# ./lib/berkshelf/berksfile.rb:362:in `install'
# ./lib/berkshelf/cli.rb:141:in `install'
# ./lib/berkshelf/cli.rb:8:in `dispatch'
# ./lib/berkshelf/init_generator.rb:92:in `generate'
# ./spec/unit/berkshelf/init_generator_spec.rb:168:in `block (4 levels) in '
# ./spec/unit/berkshelf/init_generator_spec.rb:167:in `block (3 levels) in '

Finished in 0.24344 seconds
11 examples, 1 failure

Failed examples:

rspec ./spec/unit/berkshelf/init_generator_spec.rb:172 # Berkshelf::InitGenerator with the chef_minitest option true
```