1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
require File.expand_path('../../ant_spec_helper', __FILE__)
describe Ant, "tasks:" do
include Ant::RSpec::AntExampleGroup
before :all do
# The single example ant project these specs will validate
@output = output = "ant-file#{rand}.txt"
@message = message = ""
@ant = example_ant :basedir => "." do
property :name => "jar", :value => "spec-test.jar"
property :name => "dir", :value => "build"
taskdef :name => "jarjar", :classname => "com.tonicsystems.jarjar.JarJarTask",
:classpath => "${basedir}/test/target/jarjar.jar"
target :jar do
jar :destfile => "${jar}", :compress => "true", :index => "true" do
fileset :dir => "${dir}"
end
end
target :jarjar do
jarjar :destfile => "${jar}", :compress => "true" do
fileset :dir => "${dir}"
zipfileset :src => "./lib/jruby.jar"
end
end
macrodef :name => "greet" do
attribute :name => "msg"
sequential do
echo :message => "Hello @{msg}", :file => "#{output}"
end
end
target :greet do
greet :msg => "Ant"
end
target :rubygreet do
message << "Hello Ruby!"
end
end
end
after :all do
File.unlink(@output) if File.exist?(@output)
end
before :each do
@message.replace("")
end
describe "jar" do
subject do
@ant.project.targets["jar"]
end
it { is_expected.to have_structure([{:_name => "jar", :destfile => "spec-test.jar", :compress => "true", :index => "true",
:_children => [ { :_name => "fileset", :dir => "build" }] }]) }
it { is_expected.to have_configured_structure([{:_type => "org.apache.tools.ant.taskdefs.Jar",
:_children => [{:_type => "org.apache.tools.ant.types.FileSet"}] }]) }
end
describe "jarjar" do
subject do
@ant.project.targets["jarjar"]
end
it { is_expected.to have_structure([{:_name => "jarjar", :destfile => "spec-test.jar", :compress => "true",
:_children => [ { :_name => "fileset", :dir => "build" },
{ :_name => "zipfileset", :src => "./lib/jruby.jar" }] }]) }
it { is_expected.to have_configured_structure([{:_type => "com.tonicsystems.jarjar.JarJarTask",
:_children => [{:_type => "org.apache.tools.ant.types.FileSet"},
{:_type => "org.apache.tools.ant.types.ZipFileSet"}] }]) }
end
describe "macrodef" do
it "should be defined and invokable from a target" do
@ant.execute_target(:greet)
expect(File.read(@output)).to eq("Hello Ant")
end
end
describe "rubygreet" do
it "should execute the code block when the target is executed" do
expect(@message).to be_empty
@ant.execute_target(:rubygreet)
expect(@message).to eq("Hello Ruby!")
end
end
end
|