spec/packaging/artifact_spec.rb in vic-buildr-1.3.3 vs spec/packaging/artifact_spec.rb in vic-buildr-1.3.4

- old
+ new

@@ -69,14 +69,18 @@ it 'should have associated POM artifact' do @artifact.pom.to_hash.should == @artifact.to_hash.merge(:type=>:pom) end - it 'should have one artifact for all classifiers' do + it 'should have one POM artifact for all classifiers' do @classified.pom.to_hash.should == @classified.to_hash.merge(:type=>:pom).except(:classifier) end - + + it 'should have associated sources artifact' do + @artifact.sources_artifact.to_hash.should == @artifact.to_hash.merge(:classifier=>'sources') + end + it 'should download file if file does not exist' do lambda { @artifact.invoke }.should raise_error(Exception, /No remote repositories/) lambda { @classified.invoke }.should raise_error(Exception, /No remote repositories/) end @@ -428,11 +432,11 @@ it 'should reference artifacts defined on build.yaml by using ruby symbols' do write 'build.yaml', <<-YAML artifacts: j2ee: geronimo-spec:geronimo-spec-j2ee:jar:1.4-rc4 YAML - Buildr.application.send :load_artifacts + Buildr.application.send(:load_artifact_ns) artifact(:j2ee).to_s.pathmap('%f').should == 'geronimo-spec-j2ee-1.4-rc4.jar' end end @@ -511,11 +515,11 @@ list.size.should be(2) end end -describe Builder, '#install' do +describe Buildr, '#install' do before do @spec = 'group:id:jar:1.0' write @file = 'test.jar' end @@ -540,11 +544,11 @@ lambda { install.invoke }.should change { File.exist?(artifact(@spec).pom.to_s) }.to(true) end end -describe Builder, '#upload' do +describe Buildr, '#upload' do before do @spec = 'group:id:jar:1.0' write @file = 'test.jar' repositories.release_to = 'sftp://example.com/base' end @@ -631,9 +635,46 @@ it 'should succeed if artifact already exists' do write repositories.locate(artifact('group:id:jar:1.0')) suppress_stdout do lambda { task('artifacts').invoke }.should_not raise_error + end + end +end + + +describe Rake::Task, ' artifacts:sources' do + + before do + task('artifacts:sources').clear + repositories.remote = 'http://example.com' + end + + it 'should download sources for all specified artifacts' do + artifact 'group:id:jar:1.0' + URI.should_receive(:download).any_number_of_times.and_return { |uri, target| write target } + lambda { task('artifacts:sources').invoke }.should change { File.exist?('home/.m2/repository/group/id/1.0/id-1.0-sources.jar') }.to(true) + end + + it "should not try to download sources for the project's artifacts" do + define('foo', :version=>'1.0') { package(:jar) } + URI.should_not_receive(:download) + task('artifacts:sources').invoke + end + + describe 'when the source artifact does not exist' do + + before do + artifact 'group:id:jar:1.0' + URI.should_receive(:download).any_number_of_times.and_raise(URI::NotFoundError) + end + + it 'should not fail' do + lambda { task('artifacts:sources').invoke }.should_not raise_error + end + + it 'should inform the user' do + lambda { task('artifacts:sources').invoke }.should show_info('Failed to download group:id:jar:sources:1.0. Skipping it.') end end end