test/base/test_compiler.rb in nanoc-3.8.0 vs test/base/test_compiler.rb in nanoc-4.0.0a1
- old
+ new
@@ -1,19 +1,19 @@
# encoding: utf-8
-class Nanoc::CompilerTest < Nanoc::TestCase
+class Nanoc::Int::CompilerTest < Nanoc::TestCase
def test_compilation_rule_for
# Mock rules
rules = [mock, mock, mock]
rules[0].expects(:applicable_to?).returns(false)
rules[1].expects(:applicable_to?).returns(true)
rules[1].expects(:rep_name).returns('wrong')
rules[2].expects(:applicable_to?).returns(true)
rules[2].expects(:rep_name).returns('right')
# Create compiler
- compiler = Nanoc::Compiler.new(nil)
+ compiler = Nanoc::Int::Compiler.new(nil)
compiler.rules_collection.instance_eval { @item_compilation_rules = rules }
# Mock rep
rep = mock
rep.stubs(:name).returns('right')
@@ -32,11 +32,11 @@
rules[1].expects(:rep_name).returns('wrong')
rules[2].expects(:applicable_to?).returns(true)
rules[2].expects(:rep_name).returns('right')
# Create compiler
- compiler = Nanoc::Compiler.new(nil)
+ compiler = Nanoc::Int::Compiler.new(nil)
compiler.rules_collection.instance_eval { @item_routing_rules = rules }
# Mock rep
rep = mock
rep.stubs(:name).returns('right')
@@ -50,11 +50,11 @@
def test_filter_for_layout_with_existant_layout
# Mock site
site = mock
# Create compiler
- compiler = Nanoc::Compiler.new(site)
+ compiler = Nanoc::Int::Compiler.new(site)
compiler.rules_collection.layout_filter_mapping[/.*/] = [:erb, { foo: 'bar' }]
# Mock layout
layout = MiniTest::Mock.new
layout.expect(:identifier, '/some_layout/')
@@ -66,11 +66,11 @@
def test_filter_for_layout_with_existant_layout_and_unknown_filter
# Mock site
site = mock
# Create compiler
- compiler = Nanoc::Compiler.new(site)
+ compiler = Nanoc::Int::Compiler.new(site)
compiler.rules_collection.layout_filter_mapping[/.*/] = [:some_unknown_filter, { foo: 'bar' }]
# Mock layout
layout = MiniTest::Mock.new
layout.expect(:identifier, '/some_layout/')
@@ -82,11 +82,11 @@
def test_filter_for_layout_with_nonexistant_layout
# Mock site
site = mock
# Create compiler
- compiler = Nanoc::Compiler.new(site)
+ compiler = Nanoc::Int::Compiler.new(site)
compiler.rules_collection.layout_filter_mapping[%r{^/foo/$}] = [:erb, { foo: 'bar' }]
# Mock layout
layout = MiniTest::Mock.new
layout.expect(:identifier, '/bar/')
@@ -98,11 +98,11 @@
def test_filter_for_layout_with_many_layouts
# Mock site
site = mock
# Create compiler
- compiler = Nanoc::Compiler.new(site)
+ compiler = Nanoc::Int::Compiler.new(site)
compiler.rules_collection.layout_filter_mapping[%r{^/a/b/c/.*/$}] = [:erb, { char: 'd' }]
compiler.rules_collection.layout_filter_mapping[%r{^/a/.*/$}] = [:erb, { char: 'b' }]
compiler.rules_collection.layout_filter_mapping[%r{^/a/b/.*/$}] = [:erb, { char: 'c' }] # never used!
compiler.rules_collection.layout_filter_mapping[%r{^/.*/$}] = [:erb, { char: 'a' }]
@@ -129,12 +129,12 @@
end
end
def test_compile_rep_should_write_proper_snapshots
# Mock rep
- item = Nanoc::Item.new('<%= 1 %> <%%= 2 %> <%%%= 3 %>', {}, '/moo/')
- rep = Nanoc::ItemRep.new(item, :blah)
+ item = Nanoc::Int::Item.new('<%= 1 %> <%%= 2 %> <%%%= 3 %>', {}, '/moo/')
+ rep = Nanoc::Int::ItemRep.new(item, :blah)
# Set snapshot filenames
rep.raw_paths = {
raw: 'raw.txt',
pre: 'pre.txt',
@@ -147,23 +147,23 @@
filter :erb
filter :erb
layout '/blah/'
filter :erb
end
- rule = Nanoc::Rule.new(/blah/, :meh, rule_block)
+ rule = Nanoc::Int::Rule.new(/blah/, :meh, rule_block)
# Create layout
- layout = Nanoc::Layout.new('head <%= yield %> foot', {}, '/blah/')
+ layout = Nanoc::Int::Layout.new('head <%= yield %> foot', {}, '/blah/')
# Create site
site = mock
site.stubs(:config).returns({})
site.stubs(:items).returns([])
site.stubs(:layouts).returns([layout])
# Create compiler
- compiler = Nanoc::Compiler.new(site)
+ compiler = Nanoc::Int::Compiler.new(site)
compiler.rules_collection.expects(:compilation_rule_for).times(2).with(rep).returns(rule)
compiler.rules_collection.layout_filter_mapping[%r{^/blah/$}] = [:erb, {}]
site.stubs(:compiler).returns(compiler)
# Compile
@@ -241,11 +241,11 @@
end
File.open('content/bar.html', 'w') do |io|
io.write('<%= @items.find { |i| i.identifier == "/foo/" }.compiled_content %>')
end
- assert_raises Nanoc::Errors::RecursiveCompilation do
+ assert_raises Nanoc::Int::Errors::RecursiveCompilation do
site.compile
end
end
end
@@ -266,11 +266,11 @@
io.write "\n"
io.write "layout '*', :erb\n"
end
# Create site
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
error = assert_raises(RuntimeError) do
site.compile
end
assert_match(/^The path returned for the.*does not start with a slash. Please ensure that all routing rules return a path that starts with a slash./, error.message)
end
@@ -279,13 +279,13 @@
def test_load_should_be_idempotent
# Create site
Nanoc::CLI.run %w( create_site bar)
FileUtils.cd('bar') do
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
- compiler = Nanoc::Compiler.new(site)
+ compiler = Nanoc::Int::Compiler.new(site)
def compiler.route_reps
raise 'oh my gosh it is borken'
end
assert site.instance_eval { !@loaded }
@@ -299,11 +299,11 @@
Nanoc::CLI.run %w( create_site bar )
FileUtils.cd('bar') do
Nanoc::CLI.run %w( compile )
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
site.compile
# At this point, even the already compiled items in the previous pass
# should have their compiled content assigned, so this should work:
site.items[0].reps[0].compiled_content
@@ -328,12 +328,12 @@
io.write "\n"
io.write "layout '*', :erb\n"
end
# Compile
- site = Nanoc::Site.new('.')
- assert_raises Nanoc::Errors::CannotCreateMultipleSnapshotsWithSameName do
+ site = Nanoc::Int::Site.new('.')
+ assert_raises Nanoc::Int::Errors::CannotCreateMultipleSnapshotsWithSameName do
site.compile
end
end
end
@@ -358,11 +358,11 @@
io.write "\n"
io.write "layout '*', :erb\n"
end
# Compile
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
site.compile
# Check
assert_equal '[[[<%= @item.compiled_content(:snapshot => :aaa) %>]]]', File.read('output/index.html')
end
@@ -391,11 +391,11 @@
io.write "\n"
io.write "layout '*', :erb\n"
end
# Compile
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
site.compile
# Check
assert_equal '[stuff]', File.read('output/a/index.html')
assert_equal 'stuff', File.read('output/z/index.html')
@@ -421,11 +421,11 @@
io.write "\n"
io.write "layout '*', :erb\n"
end
# Compile
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
site.compile
# Check
assert_equal 'This is 123.', File.read('output/index.html')
end
@@ -454,11 +454,11 @@
io.write " nil\n"
io.write "end\n"
end
# Compile
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
site.compile
# Check
assert_equal '<h1>A</h1>', File.read('output/index.html')
@@ -475,11 +475,11 @@
io.write " nil\n"
io.write "end\n"
end
# Compile
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
site.compile
# Check
assert_equal '<h1>B</h1>', File.read('output/index.html')
end
@@ -506,11 +506,11 @@
io.write "\n"
io.write "layout '*', :erb\n"
end
# Compile
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
site.compile
# Check
assert_equal '@rep.name = default - @item_rep.name = default', File.read('output/index.html')
end
@@ -529,11 +529,11 @@
io.write "end\n"
io.write "\n"
io.write "layout '*', :erb\n"
end
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
site.compile
assert_equal Set.new(%w( content/blah.dat )), Set.new(Dir['content/*'])
assert_equal Set.new(%w( output/blah.dat )), Set.new(Dir['output/*'])
end
@@ -545,11 +545,11 @@
File.open('content/index.html', 'w') do |io|
io.write('stuff')
end
# Compile
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
site.compile
# Check
assert Dir['tmp/text_items/*'].empty?
end
@@ -573,14 +573,14 @@
io.write "end\n"
io.write "\n"
io.write "layout '*', :erb\n"
end
- site = Nanoc::Site.new('.')
+ site = Nanoc::Int::Site.new('.')
rep = site.items['/a/'].reps[0]
dt = site.compiler.dependency_tracker
dt.start
- assert_raises Nanoc::Errors::UnmetDependency do
+ assert_raises Nanoc::Int::Errors::UnmetDependency do
site.compiler.send :compile_rep, rep
end
dt.stop
stack = dt.instance_eval { @stack }