spec/unit/template_spec.rb in xcbootstrap-0.0.3 vs spec/unit/template_spec.rb in xcbootstrap-0.1.0

- old
+ new

@@ -6,11 +6,11 @@ let(:template_dir) { "/tmp/template/sample" } let(:project_dir) { "/tmp/output/new_project" } context 'with all fields specified' do - let(:template) { XCBootstrap::Template.new({"from" => "some/path/from","to" => "some/path/to"}, template_dir, project_dir) } + let(:template) { Template.new({"from" => "some/path/from","to" => "some/path/to"}, template_dir, project_dir) } it 'should have the from field inside the template dir' do template.from.should == "/tmp/template/sample/some/path/from" end @@ -18,30 +18,31 @@ template.to.should == "/tmp/output/new_project/some/path/to" end end context 'without the to field specified' do - let(:template) { XCBootstrap::Template.new({"from" => "some/path/from"}, template_dir, project_dir) } + let(:template) { Template.new({"from" => "some/path/from"}, template_dir, project_dir) } it 'should use the from field as the to' do template.to.should == "/tmp/output/new_project/some/path/from" end end context 'with the template name in the from path' do - let(:template) { XCBootstrap::Template.new({"from" => "some/path/including/sample/in/path"}, template_dir, project_dir) } + let(:template) { Template.new({"from" => "some/path/including/sample/in/path"}, template_dir, project_dir) } it 'should use the from field with the template name replaces with the project name' do template.to.should == "/tmp/output/new_project/some/path/including/new_project/in/path" end end context 'when processing the file' do - let(:template) { XCBootstrap::Template.new({"from" => "path/to/file"}, template_dir, project_dir) } + let(:template) { Template.new({"from" => "path/to/file"}, template_dir, project_dir) } before(:each) do File.stub(:binary?).and_return(false) + File.stub(:image?).and_return(false) FileUtils.mkdir_p "/tmp/template/sample/path/to/" File.open "/tmp/template/sample/path/to/file", "w" do |from_file| from_file.puts "content including sample name" end @@ -64,22 +65,31 @@ File.read("/tmp/output/new_project/path/to/file").should_not include("sample") File.read("/tmp/output/new_project/path/to/file").should include("new_project") end end - context 'when processing a binary file' do - let(:template) { XCBootstrap::Template.new({"from" => "path/to/binary/file"}, template_dir, project_dir) } + context 'when processing binary and image files' do + let(:template) { Template.new({"from" => "path/to/binary/file"}, template_dir, project_dir) } before(:each) do - File.stub(:binary?).and_return(true) - FileUtils.mkdir_p "/tmp/template/sample/path/to/binary" File.open "/tmp/template/sample/path/to/binary/file", "wb" do |from_file| from_file.puts "content including sample name" end end - it 'should not replace occurances of the template name' do + it 'should not replace occurances of the template name in binary files' do + File.stub(:binary?).and_return(true) + File.stub(:image?).and_return(false) + + template.process + File.read("/tmp/output/new_project/path/to/binary/file").should include("sample") + end + + it 'should not replace occurances of the template name in image files' do + File.stub(:binary?).and_return(false) + File.stub(:image?).and_return(true) + template.process File.read("/tmp/output/new_project/path/to/binary/file").should include("sample") end end end \ No newline at end of file