test/base/test_compiler_dsl.rb in nanoc-3.4.1 vs test/base/test_compiler_dsl.rb in nanoc-3.4.2

- old
+ new

@@ -15,61 +15,89 @@ def test_layout # TODO implement end def test_passthrough - # Create site - Nanoc::CLI.run %w( create_site bar) - FileUtils.cd('bar') do - # Create rep - item = Nanoc::Item.new('foo', { :extension => 'bar' }, '/foo/') - rep = Nanoc::ItemRep.new(item, :default) + with_site do + # Create rules + File.open('Rules', 'w') do |io| + io.write <<EOS +passthrough "/robots/" + +compile '*' do ; end +route '*' do ; item.identifier.chop + '-xyz' + item[:extension] ; end +EOS + end - # Create other necessary stuff + # Create items + assert Dir['content/*'].empty? + File.open('content/robots.txt', 'w') do |io| + io.write "Hello I am robots" + end + + # Compile site = Nanoc::Site.new('.') - site.items << item - compiler = site.compiler - dsl = site.compiler.rules_collection.dsl + site.compile - # Create rule - dsl.passthrough '/foo/' - - # Route and compile - rule = compiler.rules_collection.routing_rule_for(rep) - path = rule.apply_to(rep, :compiler => compiler) - compiler.send :compile_rep, rep - - # Check result - assert_equal 'foo', rep.compiled_content - assert_equal '/foo.bar', path + # Check paths + assert_equal [ 'output/robots.txt' ], Dir['output/*'] end end def test_passthrough_no_ext - # Create site - Nanoc::CLI.run %w( create_site bar) - FileUtils.cd('bar') do - # Create rep - item = Nanoc::Item.new('foo', { :extension => nil }, '/foo/') - rep = Nanoc::ItemRep.new(item, :default) + with_site do + # Create rules + File.open('Rules', 'w') do |io| + io.write <<EOS +passthrough "/foo/" +EOS + end - # Create other necessary stuff + # Create items + assert Dir['content/*'].empty? + File.open('content/foo', 'w') do |io| + io.write "Hello I am foo" + end + + # Compile site = Nanoc::Site.new('.') - site.items << item - compiler = site.compiler - dsl = site.compiler.rules_collection.dsl + site.compile - # Create rule - dsl.passthrough '/foo/' + # Check paths + assert_equal [ 'output/foo' ], Dir['output/*'] + end + end - # Route and compile - rule = compiler.rules_collection.routing_rule_for(rep) - path = rule.apply_to(rep, :compiler => compiler) - compiler.send :compile_rep, rep + def test_passthrough_priority + with_site do + # Create rules + File.open('Rules', 'w') do |io| + io.write <<EOS +compile '*' do + filter :erb +end - # Check result - assert_equal 'foo', rep.compiled_content - assert_equal '/foo', path +route '*' do + item.identifier + 'index.html' +end + +passthrough "/foo/" +EOS + end + + # Create items + assert Dir['content/*'].empty? + File.open('content/foo.txt', 'w') do |io| + io.write "Hello I am <%= 'foo' %>" + end + + # Compile + site = Nanoc::Site.new('.') + site.compile + + # Check paths + assert_equal [ 'output/foo' ], Dir['output/*'] + assert_equal [ 'output/foo/index.html' ], Dir['output/foo/*'] end end def test_identifier_to_regex_without_wildcards # Create compiler DSL