Last active
July 12, 2016 18:43
-
-
Save jacoelho/aa62507263614cfaa2d133902df8b5a5 to your computer and use it in GitHub Desktop.
simple chefspec example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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