Skip to content

Commit

Permalink
Replace nested steps.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Crump committed Jul 22, 2012
1 parent fb76dc0 commit 66cc40e
Show file tree
Hide file tree
Showing 12 changed files with 833 additions and 924 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.gem
*.html
*.rbc
*.swp
coverage
doc
tmp
Expand Down
66 changes: 8 additions & 58 deletions features/step_definitions/cookbook_file_steps.rb
Original file line number Diff line number Diff line change
@@ -1,65 +1,15 @@
Given /^a Chef cookbook with a recipe that declares a cookbook file resource$/ do
steps %Q{
Given a file named "cookbooks/example/files/default/hello-world.txt" with:
"""
hello world!
"""
And a file named "cookbooks/example/recipes/default.rb" with:
"""ruby
cookbook_file "hello-world.txt"
"""
}
Given 'a Chef cookbook with a recipe that declares a cookbook file resource' do
recipe_with_cookbook_file
end

Given /^a Chef cookbook with a recipe that sets cookbook file ownership$/ do
steps %q{
Given a file named "cookbooks/example/files/default/hello-world.txt" with:
"""
hello world!
"""
And a file named "cookbooks/example/recipes/default.rb" with:
"""ruby
cookbook_file "hello-world.txt" do
owner "user"
group "group"
end
"""
And a file named "hello-world.txt" with:
"""
Hello world!
"""
}
@original_stat = owner_and_group 'hello-world.txt'
Given 'a Chef cookbook with a recipe that sets cookbook file ownership' do
recipe_sets_file_ownership(:cookbook_file)
end

Given /^the recipe has a spec example that expects the cookbook file to be declared$/ do
steps %q{
Given a file named "cookbooks/example/spec/default_spec.rb" with:
"""ruby
require "chefspec"
describe "example::default" do
let(:chef_run) {ChefSpec::ChefRunner.new.converge 'example::default'}
it "should create hello-world.txt" do
chef_run.should create_cookbook_file 'hello-world.txt'
end
end
"""
}
Given 'the recipe has a spec example that expects the cookbook file to be declared' do
spec_expects_file(:cookbook_file)
end

Given /^the recipe has a spec example that expects the cookbook file to be set to be owned by a specific user$/ do
steps %q{
Given a file named "cookbooks/example/spec/default_spec.rb" with:
"""ruby
require "chefspec"
describe "example::default" do
let(:chef_run) {ChefSpec::ChefRunner.new.converge 'example::default'}
it "should set file ownership" do
chef_run.cookbook_file('hello-world.txt').should be_owned_by('user', 'group')
end
end
"""
}
Given 'the recipe has a spec example that expects the cookbook file to be set to be owned by a specific user' do
spec_expects_file_with_ownership(:cookbook_file)
end
69 changes: 13 additions & 56 deletions features/step_definitions/cookbook_steps.rb
Original file line number Diff line number Diff line change
@@ -1,70 +1,27 @@
Given /^a Chef cookbook with a recipe that logs a node attribute$/ do
steps %q{
Given a file named "cookbooks/example/recipes/default.rb" with:
"""ruby
log "The value of node.foo is: #{node.foo}"
"""
}
Given 'a Chef cookbook with a recipe that logs a node attribute' do
recipe_logs_node_attribute
end

Given /^the recipe has a spec example that sets a node attribute$/ do
steps %q{
Given a file named "cookbooks/example/spec/default_spec.rb" with:
"""ruby
require "chefspec"
describe "example::default" do
let(:chef_run) { ChefSpec::ChefRunner.new(:log_level => :debug){|n| n.foo = 'bar'}.converge 'example::default' }
it "should log the node foo" do
chef_run.should log "The value of node.foo is: bar"
end
end
"""
}
Given 'the recipe has a spec example that sets a node attribute' do
spec_sets_node_attribute
end

Given /^the recipe has a spec example that overrides the operating system to '([^']+)'$/ do |operating_system|
@operating_system = operating_system
steps %Q{
Given a file named "cookbooks/example/spec/default_spec.rb" with:
"""ruby
require "chefspec"
describe "example::default" do
let(:chef_run) { ChefSpec::ChefRunner.new(:log_level => :debug) }
it "should log the node platform" do
chef_run.node.automatic_attrs[:platform] = '#{operating_system}'
chef_run.converge('example::default').should log 'I am running on the #{operating_system} platform.'
end
end
"""
}
spec_overrides_operating_system(operating_system)
end

When /^the recipe example is successfully run$/ do
steps %q{
When I successfully run `rspec cookbooks/example/spec/`
Then it should pass with:
"""
, 0 failures
"""
}
When 'the recipe example is successfully run' do
run_examples_successfully
end

When /^the recipe example is unsuccessfully run$/ do
steps %q{
When I run `rspec cookbooks/example/spec/`
Then it should fail with:
"""
No such file or directory
"""
}
When 'the recipe example is unsuccessfully run' do
run_examples_unsuccessfully('No such file or directory')
end

Then /^the recipe will see the node attribute set in the spec example$/ do
step %q{the stdout should contain "Processing log[The value of node.foo is: bar]"}
Then 'the recipe will see the node attribute set in the spec example' do
recipe_sees_correct_attribute_value
end

Then /^the resources declared for the operating system will be available within the example$/ do
step %Q{the stdout should contain "Processing log[I am running on the #{@operating_system} platform.]"}
Then 'the resources declared for the operating system will be available within the example' do
recipe_sees_correct_operating_system
end
46 changes: 8 additions & 38 deletions features/step_definitions/execute_steps.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
Given /^a Chef cookbook with a recipe that declares an execute resource$/ do
steps %q{
Given a file named "cookbooks/example/recipes/default.rb" with:
"""ruby
execute "print_hello_world" do
command "echo Hello World!"
action :run
end
"""
}
Given 'a Chef cookbook with a recipe that declares an execute resource' do
recipe_executes_command
end

Given /^the recipe has a spec example that expects the command to be executed$/ do
steps %q{
Given a file named "cookbooks/example/spec/default_spec.rb" with:
"""ruby
require "chefspec"
describe "example::default" do
let(:chef_run) {ChefSpec::ChefRunner.new.converge 'example::default'}
it "should print hello world" do
chef_run.should execute_command 'echo Hello World!'
end
end
"""
}
Given 'the recipe has a spec example that expects the command to be executed' do
spec_expects_command
end

Given /^a Chef cookbook with a recipe that has conditional execution based on operating system$/ do
steps %q{
Given a file named "cookbooks/example/recipes/default.rb" with:
"""ruby
case node.platform
when "leprechaun", "sprite", "balloon"
log("I am running on the #{node.platform} platform.")
else
log("This recipe is only supported on Leprechaun flavoured distros at this time.") { level :error }
end
"""
}
Given 'a Chef cookbook with a recipe that has conditional execution based on operating system' do
recipe_switches_on_operating_system
end

Then /^the command will not have been executed$/ do
step %q{the stdout should not contain "Hello World!"}
Then 'the command will not have been executed' do
command_not_executed
end
Loading

0 comments on commit 66cc40e

Please sign in to comment.