test/cli/commands/test_compile.rb in nanoc-3.8.0 vs test/cli/commands/test_compile.rb in nanoc-4.0.0a1

- old
+ new

@@ -1,13 +1,13 @@ # encoding: utf-8 class Nanoc::CLI::Commands::CompileTest < Nanoc::TestCase def test_profiling_information with_site do |_site| - Nanoc::CLI.run %w( create_item foo ) - Nanoc::CLI.run %w( create_item bar ) - Nanoc::CLI.run %w( create_item baz ) + File.open('content/foo.md', 'w') { |io| io << 'asdf' } + File.open('content/bar.md', 'w') { |io| io << 'asdf' } + File.open('content/baz.md', 'w') { |io| io << 'asdf' } File.open('Rules', 'w') do |io| io.write "compile '*' do\n" io.write " filter :erb\n" io.write "end\n" @@ -27,13 +27,13 @@ end end def test_auto_prune with_site do |_site| - Nanoc::CLI.run %w( create_item foo ) - Nanoc::CLI.run %w( create_item bar ) - Nanoc::CLI.run %w( create_item baz ) + File.open('content/foo.md', 'w') { |io| io << 'asdf' } + File.open('content/bar.md', 'w') { |io| io << 'asdf' } + File.open('content/baz.md', 'w') { |io| io << 'asdf' } File.open('Rules', 'w') do |io| io.write "compile '*' do\n" io.write " filter :erb\n" io.write "end\n" @@ -68,13 +68,13 @@ end end def test_auto_prune_with_exclude with_site do |_site| - Nanoc::CLI.run %w( create_item foo ) - Nanoc::CLI.run %w( create_item bar ) - Nanoc::CLI.run %w( create_item baz ) + File.open('content/foo.md', 'w') { |io| io << 'asdf' } + File.open('content/bar.md', 'w') { |io| io << 'asdf' } + File.open('content/baz.md', 'w') { |io| io << 'asdf' } File.open('Rules', 'w') do |io| io.write "compile '*' do\n" io.write " filter :erb\n" io.write "end\n" @@ -150,20 +150,20 @@ end end def test_file_action_printer_normal # Create data - item = Nanoc::Item.new('content', {}, '/') - rep = Nanoc::ItemRep.new(item, :default) - rep.raw_path = 'output/foo.txt' + item = Nanoc::Int::Item.new('content', {}, '/') + rep = Nanoc::Int::ItemRep.new(item, :default) + rep.raw_paths[:last] = 'output/foo.txt' rep.compiled = true # Listen listener = new_file_action_printer([rep]) listener.start - Nanoc::NotificationCenter.post(:compilation_started, rep) - Nanoc::NotificationCenter.post(:rep_written, rep, rep.raw_path, false, true) + Nanoc::Int::NotificationCenter.post(:compilation_started, rep) + Nanoc::Int::NotificationCenter.post(:rep_written, rep, rep.raw_path, false, true) listener.stop # Check assert_equal 1, listener.events.size assert_equal :high, listener.events[0][:level] @@ -172,18 +172,18 @@ assert_in_delta 0.0, listener.events[0][:duration], 1.0 end def test_file_action_printer_skip # Create data - item = Nanoc::Item.new('content', {}, '/') - rep = Nanoc::ItemRep.new(item, :default) - rep.raw_path = 'output/foo.txt' + item = Nanoc::Int::Item.new('content', {}, '/') + rep = Nanoc::Int::ItemRep.new(item, :default) + rep.raw_paths[:last] = 'output/foo.txt' # Listen listener = new_file_action_printer([rep]) listener.start - Nanoc::NotificationCenter.post(:compilation_started, rep) + Nanoc::Int::NotificationCenter.post(:compilation_started, rep) listener.stop # Check assert_equal 1, listener.events.size assert_equal :low, listener.events[0][:level] @@ -191,9 +191,15 @@ assert_equal 'output/foo.txt', listener.events[0][:path] assert_nil listener.events[0][:duration] end def new_file_action_printer(reps) + # Ensure CLI is loaded + begin + Nanoc::CLI.run(%w( help %)) + rescue SystemExit + end + listener = Nanoc::CLI::Commands::Compile::FileActionPrinter.new(reps: reps) def listener.log(level, action, path, duration) @events ||= [] @events << {