spec/vendorer_spec.rb in vendorer-0.1.10 vs spec/vendorer_spec.rb in vendorer-0.1.11

- old
+ new

@@ -11,11 +11,11 @@ after do `rm -rf spec/tmp` end def write(file, content) - File.open(file,'w'){|f| f.write(content) } + File.open(file, 'w') { |f| f.write(content) } end def read(file) File.read(file) end @@ -136,13 +136,13 @@ it "does not change file modes" do simple_vendorfile vendorer run 'chmod 711 public/javascripts/jquery.min.js' - lambda{ + lambda { vendorer 'update' - }.should_not change{ run('ls -l public/javascripts').split("\n") } + }.should_not change { run('ls -l public/javascripts').split("\n") } end end context "with a passed block" do before do @@ -168,11 +168,11 @@ it "can download from remote" do write 'Vendorfile', "folder 'vendor/plugins/parallel_tests', 'https://github.com/grosser/parallel_tests.git'" vendorer ls('vendor/plugins').should == ["parallel_tests"] - read('vendor/plugins/parallel_tests/Gemfile').should include('parallel') + read('vendor/plugins/parallel_tests/Gemfile').should include('cucumber') end it "reports errors when the Vendorfile is broken" do write 'Vendorfile', "folder 'vendor/plugins/parallel_tests', 'https://blob'" output = vendorer '', :raise => true @@ -278,11 +278,11 @@ read('public/javascripts/jquery.js').should include('jQuery') end it "can update a nested file" do vendorer - write('public/javascripts/jquery.js','Foo') + write('public/javascripts/jquery.js', 'Foo') vendorer 'update' read('public/javascripts/jquery.js').should include('jQuery') end it "can update a whole folder" do @@ -291,12 +291,12 @@ file 'jquery.js', 'http://code.jquery.com/jquery-latest.min.js' end file 'xxx.js', 'http://code.jquery.com/jquery-latest.min.js' " vendorer - write('public/javascripts/jquery.js','Foo') - write('xxx.js','Foo') + write('public/javascripts/jquery.js', 'Foo') + write('xxx.js', 'Foo') vendorer 'update public/javascripts' read('xxx.js').should == "Foo" read('public/javascripts/jquery.js').should include('jQuery') end @@ -328,13 +328,14 @@ run "cd #{folder} && #{command}" run "cd #{folder} && git add ." run "cd #{folder} && git commit -am 'initial'" end - let(:vendorer){ + let(:vendorer) { v = Vendorer.new - def v.puts(x);end # silence + def v.puts(x) # silence + end v } it "installs submodules" do create_git_repo 'a', 'git submodule add `cd ../../../.git && pwd` sub' @@ -420,11 +421,11 @@ read("Vendorfile").should include("folder") end it "created Vendorfile contains commented out examples" do Vendorer.new('init').init - read("Vendorfile").split("\n").each{|l| l.should =~ /^(#|\s*$)/ } + read("Vendorfile").split("\n").each { |l| l.should =~ /^(#|\s*$)/ } end it "created Vendorfile contains many examples" do Vendorer.new('init').init read("Vendorfile").should include("folder 'vendor/") @@ -437,8 +438,110 @@ read("Vendorfile").should_not include("vendorer init") read("Vendorfile").should_not include("Gemfile") read("Vendorfile").should_not include("gem install") read("Vendorfile").should_not include("```") end + end + end + + describe "#from" do + it "returns to normal after the block" do + write "Vendorfile", " + from '../../.git' do + file 'Readme.md' + end + file 'jquery.js', 'http://code.jquery.com/jquery-latest.min.js' + " + vendorer + ls(".").should =~ ['Readme.md', 'Vendorfile', 'jquery.js'] + read('jquery.js').should include("jQuery") + end + + it "can checkout a specific version" do + write "Vendorfile", " + from '../../.git', :tag => 'v0.1.0' do + file 'lib/vendorer/version.rb' + end + " + vendorer + read('lib/vendorer/version.rb').should include("0.1.0") + end + + context "with file" do + it "copies" do + write "Vendorfile", " + from '../../.git' do + file 'Readme.md' + end + " + vendorer + ls(".").should == ['Readme.md', 'Vendorfile'] + end + + it "copies to/from a nested location" do + write "Vendorfile", " + from '../../.git' do + file 'foo/bar/renamed.rb', 'lib/vendorer.rb' + end + " + vendorer + ls(".").should == ['foo', 'Vendorfile'] + ls("./foo/bar").should == ['renamed.rb'] + end + + it "renames" do + write "Vendorfile", " + from '../../.git' do + file 'Readme.renamed', 'Readme.md' + end + " + vendorer + ls(".").should == ['Readme.renamed', 'Vendorfile'] + end + end + + context "with folder" do + it "copies" do + write "Vendorfile", " + from '../../.git' do + folder 'lib' + end + " + vendorer + ls(".").should == ['lib', 'Vendorfile'] + ls("./lib").should == ['vendorer', 'vendorer.rb'] + end + + it "copies to/from a nested location" do + write "Vendorfile", " + from '../../.git' do + folder 'foo/bar', 'lib/vendorer' + end + " + vendorer + ls(".").should == ['foo', 'Vendorfile'] + ls("./foo/bar").should == ['version.rb'] + end + + it "renames" do + write "Vendorfile", " + from '../../.git' do + folder 'foo', 'lib' + end + " + vendorer + ls(".").should == ['foo', 'Vendorfile'] + ls("./foo").should == ['vendorer', 'vendorer.rb'] + end + end + + it "gives 'not found' error for non-existent file" do + write "Vendorfile", " + from '../../.git', :tag => 'b1e6460' do + file 'bogus' + end + " + output = vendorer '', :raise => true + output.should include("'bogus' not found in ../../.git") end end end