sethvargo/chefspec — pull request #419 by trinitronx (2014-04-18 21:55:14+00:00)
Title: Add Feature: stub_environment macro method

Hi Seth!

I've decided to take you up on the challenge to implement a better way to mock environments... so here is my solution:

```ruby
stub_environment('name')
```

Can't get much easier than that!

You just pass in a `String` or `Symbol` for the name and `node.chef_environment` & `node.environment` are now set for testing the recipe. It works within a `ChefSpec::Runner` block, or just in any old rspec `it` block. I've also added the feature to pass `stub_environment` a block in order to mock out any attributes set in the environment. This block is evaluated within the instance of `Chef::Environment` so [any methods](http://www.rubydoc.info/github/opscode/chef/master/Chef/Environment) available within that class can be accessed.

For example:

```ruby
stub_environment('foo') do
default_attributes({ 'foo' => 'bar' })
end
```

To top it off I've added cucumber & rspec tests for the many actual use cases and also documented it in the README