Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, a common practice is to extract <code>ChefRunner</code> instantiation to <code>let</code> helper. You can also include all Fauxhai configuration there:</p> <pre><code>let(:chef_run) do ChefSpec::ChefRunner.new(platform: platform, version: version) do |node| node.set['foo']['bar'] = 'baz' # .... end.converge('foo::default') end it "installs foo" do expect(chef_run).to install_package 'foo' end </code></pre> <p>The <code>expect</code> syntax seems to be <a href="https://github.com/rspec/rspec-expectations/blob/master/Should.md" rel="nofollow">recommended</a> over <code>should</code>. But in this example I would use a one-liner:</p> <pre><code>subject do ChefSpec::ChefRunner.new(platform: platform, version: version).converge('foo::default') end it { should install_package 'foo' } </code></pre> <p>To clean up the looping a bit you can use <a href="https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples" rel="nofollow">RSpec's shared examples</a>. A bit more extended example:</p> <pre><code>require 'chefspec' shared_examples 'foo' do |platform, version| context "on #{platform} #{version}" do let(:users) { %w[user1 user2] } let(:chef_run) do ChefSpec::ChefRunner.new(platform: platform, version: version) do |node| node.set['foo']['users'] = users end.converge('foo::default') end subject { chef_run } it { should install_package 'foo' } it "creates specified users" do users.each { |u| expect(chef_run).to create_user u } end end end describe 'foo::default' do platforms = { 'debian' =&gt; ['6.0.5'], 'ubuntu' =&gt; ['12.04', '10.04'], 'centos' =&gt; ['5.8', '6.0', '6.3'], 'redhat' =&gt; ['5.8', '6.3'], 'mac_os_x' =&gt; ['10.6.8', '10.7.4', '10.8.2'], 'windows' =&gt; ['2008R2'] } platforms.each do |platform, versions| versions.each do |version| include_examples 'foo', platform, version end end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload