#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../lib/masterview' ) require 'masterview/extras/watcher.rb' class TestTemplateFileWatcher < Test::Unit::TestCase CurrentPath = File.dirname(__FILE__) MVTemplateDir = File.join(CurrentPath, '../examples') MVFilenamePattern = '*.html' TmpOutputDir = File.join(CurrentPath, '../tmp/views') MVProductFile = File.join(CurrentPath, '../examples/product.html') def setup FileUtils.remove_dir(TmpOutputDir, true) end def test_a_run files_run = MasterView::TemplateFileWatcher.check(MVTemplateDir, MVFilenamePattern, true) do |f| MasterView::Parser.parse_file( f, TmpOutputDir ) end assert_equal [MVProductFile], files_run assert File.exist?(TmpOutputDir+'/layouts/product.rhtml') assert File.exist?(TmpOutputDir+'/product/_form.rhtml') assert File.exist?(TmpOutputDir+'/product/edit.rhtml') assert File.exist?(TmpOutputDir+'/product/list.rhtml') assert File.exist?(TmpOutputDir+'/product/new.rhtml') assert File.exist?(TmpOutputDir+'/product/show.rhtml') end def test_b_no_change files_run = MasterView::TemplateFileWatcher.check(MVTemplateDir, MVFilenamePattern, true) do |f| MasterView::Parser.parse_file( f, TmpOutputDir ) end assert_equal [], files_run end def test_c_file_changed_run FileUtils.touch MVProductFile files_run = MasterView::TemplateFileWatcher.check(MVTemplateDir, MVFilenamePattern, true) do |f| MasterView::Parser.parse_file( f, TmpOutputDir ) end assert_equal [MVProductFile], files_run end end