Skip to content

Instantly share code, notes, and snippets.

@jacoelho
Last active July 12, 2016 18:43
Show Gist options
  • Save jacoelho/aa62507263614cfaa2d133902df8b5a5 to your computer and use it in GitHub Desktop.
Save jacoelho/aa62507263614cfaa2d133902df8b5a5 to your computer and use it in GitHub Desktop.
simple chefspec example
require "spec_helper"
context "test_example" do
let(:chef_conf) do
ChefSpec::SoloRunner.new cookbook_path: %w(./test/cookbooks ../), # import test and example cookbook
step_into: %w(example_topic) # dive inside example_topic
end
let(:shellout) { double("shellout") } # setup shellout double
before do
allow(Mixlib::ShellOut).to receive(:new).and_return(shellout)
allow(shellout).to receive_messages(
:run_command => nil,
:error! => nil,
:live_stream => nil,
:live_stream= => nil
)
end
describe "topic create" do
let(:chef_run) { chef_conf.converge("test_example::create") }
it "converges successfully" do
allow(shellout).to receive(:stdout).and_return("", "Created topic")
expect { chef_run }.to_not raise_error
expect(chef_run).to create_example_topic("test") # custom matcher in action
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment