Permalink
Browse files

Replace nested steps.

  • Loading branch information...
1 parent fb76dc0 commit 66cc40eed4a88d1314523934c159d7e9208758da @acrmp acrmp committed Jul 22, 2012
View
@@ -3,6 +3,7 @@
*.gem
*.html
*.rbc
+*.swp
coverage
doc
tmp
@@ -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
@@ -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
@@ -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
Oops, something went wrong.

0 comments on commit 66cc40e

Please sign in to comment.