spec/unit/berkshelf/init_generator_spec.rb in berkshelf-0.4.0.rc1 vs spec/unit/berkshelf/init_generator_spec.rb in berkshelf-0.4.0.rc2
- old
+ new
@@ -2,51 +2,151 @@
module Berkshelf
describe InitGenerator do
subject { InitGenerator }
- let(:target_root) { tmp_path.join("some_cookbook") }
+ let(:target) { tmp_path.join("some_cookbook") }
context "with default options" do
before do
- generator = subject.new([target_root])
+ generator = subject.new([target])
capture(:stdout) { generator.invoke_all }
end
specify do
- target_root.should have_structure {
+ target.should have_structure {
file "Berksfile"
+ file "Gemfile" do
+ contains "gem 'berkshelf'"
+ end
no_file "chefignore"
}
end
end
context "with a chefignore" do
before do
- generator = subject.new([target_root], chefignore: true)
+ generator = subject.new([target], chefignore: true)
capture(:stdout) { generator.invoke_all }
end
specify do
- target_root.should have_structure {
+ target.should have_structure {
file "Berksfile"
file "chefignore"
}
end
end
context "with a metadata entry in the Berksfile" do
before do
- generator = subject.new([target_root], metadata_entry: true)
+ generator = subject.new([target], metadata_entry: true)
capture(:stdout) { generator.invoke_all }
end
specify do
- target_root.should have_structure {
+ target.should have_structure {
file "Berksfile" do
contains "metadata"
end
}
+ end
+ end
+
+ context "with the vagrant option true" do
+ before do
+ generator = subject.new([target], vagrant: true)
+ quietly { generator.invoke_all }
+ end
+
+ specify do
+ target.should have_structure {
+ file "Vagrantfile" do
+ contains "recipe[some_cookbook::default]"
+ end
+ file "Gemfile" do
+ contains "gem 'vagrant'"
+ end
+ directory "cookbooks"
+ }
+ end
+ end
+
+ context "with the git option true" do
+ before do
+ generator = subject.new([target], git: true)
+ capture(:stdout) { generator.invoke_all }
+ end
+
+ specify do
+ target.should have_structure {
+ file ".gitignore"
+ }
+ end
+ end
+
+ context "with the foodcritic option true" do
+ before do
+ generator = subject.new([target], foodcritic: true)
+ capture(:stdout) { generator.invoke_all }
+ end
+
+ specify do
+ target.should have_structure {
+ file "Thorfile" do
+ contains "require 'thor/foodcritic'"
+ end
+ file "Gemfile" do
+ contains "gem 'thor-foodcritic'"
+ end
+ }
+ end
+ end
+
+ context "with the scmversion option true" do
+ before do
+ generator = subject.new([target], scmversion: true)
+ capture(:stdout) { generator.invoke_all }
+ end
+
+ specify do
+ target.should have_structure {
+ file "Thorfile" do
+ contains "require 'thor/scmversion'"
+ end
+ file "Gemfile" do
+ contains "gem 'thor-scmversion'"
+ end
+ }
+ end
+ end
+
+ context "with the bundler option true" do
+ before do
+ generator = subject.new([target], no_bundler: true)
+ capture(:stdout) { generator.invoke_all }
+ end
+
+ specify do
+ target.should have_structure {
+ no_file "Gemfile"
+ }
+ end
+ end
+
+ context "given a value for the cookbook_name option" do
+ it "sets the value of cookbook_name attribute to the specified option" do
+ generator = subject.new([target], cookbook_name: "nautilus")
+
+ generator.send(:cookbook_name).should eql("nautilus")
+ end
+ end
+
+ context "when no value for cookbook_name option is specified" do
+ it "infers the name of the cookbook from the directory name" do
+ generator = subject.new([target])
+
+ generator.send(:cookbook_name).should eql("some_cookbook")
end
end
end
end