You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by vb...@apache.org on 2008/09/23 21:12:17 UTC
svn commit: r698287 - /incubator/buildr/trunk/spec/core/common_spec.rb
Author: vborja
Date: Tue Sep 23 12:12:17 2008
New Revision: 698287
URL: http://svn.apache.org/viewvc?rev=698287&view=rev
Log:
specs for Filter::Mapper and erb filter type
Modified:
incubator/buildr/trunk/spec/core/common_spec.rb
Modified: incubator/buildr/trunk/spec/core/common_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/core/common_spec.rb?rev=698287&r1=698286&r2=698287&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/core/common_spec.rb (original)
+++ incubator/buildr/trunk/spec/core/common_spec.rb Tue Sep 23 12:12:17 2008
@@ -376,6 +376,43 @@
end
end
+ it 'should use erb when given a binding' do
+ 1.upto(4) { |i| write "src/file#{i}", "file#{i} with <%= key1 %> and <%= key2 * 2 %>" }
+ key1 = 'value1'
+ key2 = 12
+ @filter.from('src').into('target').using(binding).run
+ Dir['target/*'].each do |file|
+ read(file).should eql("#{File.basename(file)} with value1 and 24")
+ end
+ end
+
+ it 'should apply hash mapping using erb' do
+ 1.upto(4) { |i| write "src/file#{i}", "file#{i} with <%= key1 %> and <%= key2 * 2 %>" }
+ @filter.from('src').into('target').using(:erb, 'key1'=>'value1', 'key2'=> 12).run
+ Dir['target/*'].each do |file|
+ read(file).should eql("#{File.basename(file)} with value1 and 24")
+ end
+ end
+
+ it 'should use an object binding when using erb' do
+ 1.upto(4) { |i| write "src/file#{i}", "file#{i} with <%= key1 %> and <%= key2 * 2 %>" }
+ obj = Struct.new(:key1, :key2).new('value1', 12)
+ @filter.from('src').into('target').using(:erb, obj).run
+ Dir['target/*'].each do |file|
+ read(file).should eql("#{File.basename(file)} with value1 and 24")
+ end
+ end
+
+ it 'should use a given block context when using erb' do
+ 1.upto(4) { |i| write "src/file#{i}", "file#{i} with <%= key1 %> and <%= key2 * 2 %>" }
+ key1 = 'value1'
+ key2 = 12
+ @filter.from('src').into('target').using(:erb){}.run
+ Dir['target/*'].each do |file|
+ read(file).should eql("#{File.basename(file)} with value1 and 24")
+ end
+ end
+
it 'should using Maven mapper by default' do
@filter.using('key1'=>'value1', 'key2'=>'value2').mapper.should eql(:maven)
end
@@ -452,6 +489,32 @@
end
end
+describe Filter::Mapper do
+
+ module MooMapper
+ def moo_config(*args, &block)
+ raise ArgumentError, "Expected moo block" unless block_given?
+ { :moos => args, :callback => block }
+ end
+
+ def moo_result(content, path = nil)
+ content.gsub(/moo+/i) do |str|
+ moos = yield :moos # same than config[:moos]
+ moo = moos[str.size - 3] || str
+ config[:callback].call(moo)
+ end
+ end
+ end
+
+ it 'should allow plugable mapping types' do
+ mapper = Filter::Mapper.new.extend(MooMapper)
+ mapper.using(:moo, 'ooone', 'twoo') do |str|
+ i = nil; str.capitalize.gsub(/\w/) { |s| s.send( (i = !i) ? 'upcase' : 'downcase' ) }
+ end
+ mapper.result('Moo cow, mooo cows singing mooooo').should == 'OoOnE cow, TwOo cows singing MoOoOo'
+ end
+
+end
describe Buildr.method(:options) do
it 'should return an Options object' do
@@ -468,7 +531,6 @@
end
end
-
describe Buildr::Options, 'proxy.exclude' do
before do
options.proxy.http = 'http://myproxy:8080'