require_relative '../spec_helper' require 'fakefs/spec_helpers' describe 'Bootstrap' do include FakeFS::SpecHelpers context 'with a template that does not exist' do it 'should raise an error' do expect { Bootstrap.new("/tmp", "non_existant_template", "path-to-project") }.to raise_error end end context 'with a template with no manifest' do it 'should raise an error' do FileUtils.mkdir_p "/tmp/template_with_no_manifest" expect { Bootstrap.new("/tmp", "template_with_no_manifest", "path-to-project") }.to raise_error end end context 'with an invalid manifest file' do it 'should raise an error' do create_invalid_manifest_with_content "fake manifest..\n... the end" expect { Bootstrap.new("/tmp", "template_with_invalid_manifest", "path-to-project") }.to raise_error end end context 'with a manifest where files is not an array' do it 'should raise an error' do create_invalid_manifest_with_content "---\nfiles: blah" expect { Bootstrap.new("/tmp", "template_with_invalid_manifest", "path-to-project") }.to raise_error end end context 'with a manifest where files is empty' do it 'should raise an error' do create_invalid_manifest_with_content "---\nfiles: []" expect { Bootstrap.new("/tmp", "template_with_invalid_manifest", "path-to-project") }.to raise_error end end context 'with a valid template' do before(:each) do FileUtils.mkdir_p "/tmp/my_template" File.open "/tmp/my_template/manifest.yml", "w" do |from_file| from_file.puts "---" from_file.puts "files:" from_file.puts " - from: some_file.txt" end File.open "/tmp/my_template/some_file.txt", "w" do |from_file| from_file.puts "some content" end Dir.stub(:pwd).and_return("/tmp/fake-working-dir") end context 'with a relative project path' do let(:bootstrapper) { Bootstrap.new("/tmp", "my_template", "../path/to/my_project") } it 'should have the full path to the template' do bootstrapper.template_dir.should == "/tmp/my_template" end it 'should have the full path to the output project' do bootstrapper.project_dir.should == "/tmp/path/to/my_project" end context 'when the template is processed' do before(:each) do File.stub(:binary?).and_return(false) File.stub(:image?).and_return(false) bootstrapper.process end it 'should create the output project directory' do File.exists?(bootstrapper.project_dir).should be_true end it 'should copy files to the output project' do output_file = File.join bootstrapper.project_dir, "some_file.txt" File.exists?(output_file).should be_true end end end context 'with an absolute project path' do let(:bootstrapper) { Bootstrap.new("/tmp", "my_template", "/tmp/path/to/my_project") } it 'should leave the project path absolute' do bootstrapper.project_dir.should == "/tmp/path/to/my_project" end end end def create_invalid_manifest_with_content content FileUtils.mkdir_p "/tmp/template_with_invalid_manifest" File.open "/tmp/template_with_invalid_manifest/manifest.yml", "w" do |from_file| from_file.puts content end end end