require 'aruba/api' World(Aruba::Api) World(Berkshelf::RSpec::ChefAPI) Given /^a cookbook named "(.*?)"$/ do |name| steps %{ Given a directory named "#{name}" And an empty file named "#{name}/metadata.rb" } end Given /^I do not have a Berksfile$/ do in_current_dir { FileUtils.rm_f(Berkshelf::DEFAULT_FILENAME) } end Given /^I do not have a Berksfile\.lock$/ do in_current_dir { FileUtils.rm_f(Berkshelf::Lockfile::DEFAULT_FILENAME) } end Given /^I have a Berkshelf config file containing:$/ do |contents| write_file File.expand_path("~/.berkshelf/config.json"), contents end Given /^I do not have a Berkshelf config file$/ do file = File.expand_path "~/.berkshelf/config.json" remove_file file if File.exists? file end Given /^the cookbook "(.*?)" has the file "(.*?)" with:$/ do |cookbook_name, file_name, content| write_file(File.join(cookbook_name, file_name), content) end Given /^the cookbook store has the cookbooks:$/ do |cookbooks| cookbooks.raw.each do |name, version| generate_cookbook(cookbook_store, name, version) end end Given /^the cookbook store contains a cookbook "(.*?)" "(.*?)" with dependencies:$/ do |name, version, dependencies| generate_cookbook(cookbook_store, name, version, dependencies: dependencies.raw) end Then /^the cookbook store should have the cookbooks:$/ do |cookbooks| cookbooks.raw.each do |name, version| cookbook_store.should have_structure { directory "#{name}-#{version}" do file "metadata.rb" do contains version end end } end end Then /^the cookbook store should have the git cookbooks:$/ do |cookbooks| cookbooks.raw.each do |name, version, sha1| cookbook_store.should have_structure { directory "#{name}-#{sha1}" do file "metadata.rb" do contains version end end } end end Then /^the cookbook store should not have the cookbooks:$/ do |cookbooks| cookbooks.raw.each do |name, version| cookbook_store.should_not have_structure { directory "#{name}-#{version}" } end end Then /^I should have the cookbook "(.*?)"$/ do |name| Pathname.new(current_dir).join(name).should be_cookbook end Then /^I should have a new cookbook skeleton "(.*?)"$/ do |name| cb_path = Pathname.new(current_dir).join(name) cb_path.should have_structure { directory "attributes" directory "definitions" directory "files" do directory "default" end directory "libraries" directory "providers" directory "recipes" do file "default.rb" end directory "resources" directory "templates" do directory "default" end file ".gitignore" file "chefignore" file "Berksfile" do contains "metadata" end file "Gemfile" do contains "gem 'berkshelf'" contains "gem 'vagrant'" end file "metadata.rb" file "README.md" file "Vagrantfile" do contains "require 'berkshelf/vagrant'" contains "recipe[#{name}::default]" end } end Then /^I should have a new cookbook skeleton "(.*?)" with Foodcritic support$/ do |name| steps %Q{ Then I should have a new cookbook skeleton "#{name}" } cb_path = Pathname.new(current_dir).join(name) cb_path.should have_structure { file "Gemfile" do contains "gem 'thor-foodcritic'" end file "Thorfile" do contains "require 'thor/foodcritic'" end } end Then /^I should have a new cookbook skeleton "(.*?)" with SCMVersion support$/ do |name| steps %Q{ Then I should have a new cookbook skeleton "#{name}" } cb_path = Pathname.new(current_dir).join(name) cb_path.should have_structure { file "Gemfile" do contains "gem 'thor-scmversion'" end file "Thorfile" do contains "require 'thor/scmversion'" end } end Then /^I should have a new cookbook skeleton "(.*?)" without Bundler support$/ do |name| cb_path = Pathname.new(current_dir).join(name) cb_path.should have_structure { directory "attributes" directory "definitions" directory "files" do directory "default" end directory "libraries" directory "providers" directory "recipes" do file "default.rb" end directory "resources" directory "templates" do directory "default" end file "README.md" file "metadata.rb" file "Berksfile" do contains "metadata" end file "chefignore" file "Berksfile" no_file "Gemfile" } end Then /^I should have a new cookbook skeleton "(.*?)" without Git support$/ do |name| Pathname.new(current_dir).join(name).should have_structure { no_file ".gitignore" } end Then /^I should have a new cookbook skeleton "(.*?)" without Vagrant support$/ do |name| Pathname.new(current_dir).join(name).should have_structure { file "Gemfile" do does_not_contain "gem 'vagrant'" end no_file "Vagrantfile" } end Then /^the cookbook "(.*?)" should have the following files:$/ do |name, files| check_file_presence(files.raw.map{|file_row| File.join(name, file_row[0])}, true) end Then /^the cookbook "(.*?)" should not have the following files:$/ do |name, files| check_file_presence(files.raw.map{|file_row| File.join(name, file_row[0])}, false) end Then /^the file "(.*?)" in the cookbook "(.*?)" should contain:$/ do |file_name, cookbook_name, content| Pathname.new(current_dir).join(cookbook_name).should have_structure { file "Berksfile" do contains content end file "chefignore" } end Then /^the resulting "(.+)" Vagrantfile should contain:$/ do |cookbook_name, content| Pathname.new(current_dir).join(cookbook_name).should have_structure { file "Vagrantfile" do content.respond_to?(:raw) ? content.raw.flatten.each { |string| contains string } : contains(content) end } end Then /^the directory "(.*?)" should have the following files:$/ do |name, files| check_file_presence(files.raw.map{|file_row| File.join(name, file_row[0])}, true) end Then /^the directory "(.*?)" should not have the following files:$/ do |name, files| check_file_presence(files.raw.map{|file_row| File.join(name, file_row[0])}, false) end Then /^the file "(.*?)" in the directory "(.*?)" should not contain:$/ do |file_name, directory_name, content| Pathname.new(current_dir).join(directory_name).should_not have_structure { file "Berksfile" do contains content end } end Then /^the current directory should have the following files:$/ do |files| check_file_presence(files.raw.map{|file_row| file_row[0]}, true) end Then /^the current directory should not have the following files:$/ do |files| check_file_presence(files.raw.map{|file_row| file_row[0]}, false) end Then /^I should have a Berkshelf config file$/ do Pathname.new(ENV['HOME']).join(".berkshelf").should have_structure { file "config.json" } end