spec/unit/berkshelf/init_generator_spec.rb in berkshelf-1.1.6 vs spec/unit/berkshelf/init_generator_spec.rb in berkshelf-1.2.0.rc1

- old
+ new

@@ -1,156 +1,162 @@ require 'spec_helper' -module Berkshelf - describe InitGenerator do - subject { InitGenerator } +describe Berkshelf::InitGenerator do + subject { described_class } - let(:target) { tmp_path.join("some_cookbook") } + let(:target) { tmp_path.join("some_cookbook") } - context "with default options" do - before do - generator = subject.new([target]) - capture(:stdout) { generator.invoke_all } - end + context "with default options" do + before(:each) do + capture(:stdout) { + subject.new([target]).invoke_all + } + end - specify do - target.should have_structure { - file ".gitignore" - file "Berksfile" - file "Gemfile" do - contains "gem 'berkshelf'" - contains "gem 'vagrant'" - end - file "Vagrantfile" do - contains "require 'berkshelf/vagrant'" - contains "recipe[some_cookbook::default]" - end - no_file "chefignore" - } - end + specify do + target.should have_structure { + file ".gitignore" + file "Berksfile" + file "Gemfile" do + contains "gem 'berkshelf'" + contains "gem 'vagrant'" + end + file "Vagrantfile" do + contains "require 'berkshelf/vagrant'" + contains "recipe[some_cookbook::default]" + end + no_file "chefignore" + } end + end - context "with a chefignore" do - before do - generator = subject.new([target], chefignore: true) - capture(:stdout) { generator.invoke_all } - end + context "with a chefignore" do + before(:each) do + capture(:stdout) { + subject.new([target], chefignore: true).invoke_all + } + end - specify do - target.should have_structure { - file "Berksfile" - file "chefignore" - } + specify do + target.should have_structure { + file "Berksfile" + file "chefignore" + } + end + end + + context "with a metadata entry in the Berksfile" do + before(:each) do + Dir.mkdir target + File.open(target.join("metadata.rb"), 'w+') do |f| + f.write "" end + + capture(:stdout) { + subject.new([target], metadata_entry: true).invoke_all + } end - context "with a metadata entry in the Berksfile" do - before do - Dir.mkdir target - File.open(target.join("metadata.rb"), 'w+') do |f| - f.write "" + specify do + target.should have_structure { + file "Berksfile" do + contains "metadata" end - generator = subject.new([target], metadata_entry: true) - capture(:stdout) { generator.invoke_all } - end + } + end + end - specify do - target.should have_structure { - file "Berksfile" do - contains "metadata" - end - } - end + context "with the foodcritic option true" do + before(:each) do + capture(:stdout) { + subject.new([target], foodcritic: true).invoke_all + } 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 - specify do - target.should have_structure { - file "Thorfile" do - contains "require 'thor/foodcritic'" - end - file "Gemfile" do - contains "gem 'thor-foodcritic'" - end - } - end + context "with the scmversion option true" do + before(:each) do + capture(:stdout) { + subject.new([target], scmversion: true).invoke_all + } 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 - specify do - target.should have_structure { - file "Thorfile" do - contains "require 'thor/scmversion'" - end - file "Gemfile" do - contains "gem 'thor-scmversion'" - end - } - end + context "with the bundler option true" do + before(:each) do + capture(:stdout) { + subject.new([target], no_bundler: true).invoke_all + } 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 + 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") + 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 + 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]) + 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 + generator.send(:cookbook_name).should eql("some_cookbook") end + end - context "when skipping git" do - before do - generator = subject.new([target], skip_git: true) - capture(:stdout) { generator.invoke_all } - end + context "when skipping git" do + before(:each) do + generator = subject.new([target], skip_git: true) + capture(:stdout) { generator.invoke_all } + end - it "should not have a .git directory" do - target.should_not have_structure { - directory ".git" - } - end + it "should not have a .git directory" do + target.should_not have_structure { + directory ".git" + } end + end - context "when skipping vagrant" do - before do - generator = subject.new([target], skip_vagrant: true) - capture(:stdout) { generator.invoke_all } - end + context "when skipping vagrant" do + before(:each) do + capture(:stdout) { + subject.new([target], skip_vagrant: true).invoke_all + } + end - it "should not have a Vagrantfile" do - target.should have_structure { - no_file "Vagrantfile" - } - end + it "should not have a Vagrantfile" do + target.should have_structure { + no_file "Vagrantfile" + } end end end