Module: ChefSpec::API::Described

Defined in:
lib/chefspec/api/described.rb

Instance Method Summary collapse

Instance Method Details

#described_cookbookString

The name of the currently running cookbook spec. Given the top-level describe block is of the format:

describe 'my_cookbook::my_recipe' do
  # ...
end

The value of described_cookbook is “my_cookbook”.

Examples:

Using described_cookbook in a context block

context "#{described_recipe} installs foo" do
  # ...
end

Returns:

  • (String)


22
23
24
# File 'lib/chefspec/api/described.rb', line 22

def described_cookbook
  described_recipe.split("::").first
end

#described_recipeString

The name of the currently running recipe spec. Given the top-level describe block is of the format:

describe 'my_cookbook::my_recipe' do
  # ...
end

The value of described_recipe is “my_cookbook::my_recipe”.

Examples:

Using described_recipe in the ChefSpec::SoloRunner

let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) }

Returns:

  • (String)


42
43
44
45
46
47
48
49
# File 'lib/chefspec/api/described.rb', line 42

def described_recipe
  scope = is_a?(Class) ? self : self.class

  metahash = scope.
  metahash = metahash[:parent_example_group] while metahash.key?(:parent_example_group)

  metahash[:description].to_s
end