#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview/io' ) class TestMIO < Test::Unit::TestCase # bring test subjects into the local name space MIOTrees = MasterView::MIO::MIOTrees FileMIOTree = MasterView::MIO::FileMIOTree StringHashMIOTree = MasterView::MIO::StringHashMIOTree MTimeStringHashMIOTree = MasterView::MIO::MTimeStringHashMIOTree RailsErbCacheMIOTree = MasterView::MIO::RailsErbCacheMIOTree MVTestDir = File.expand_path( File.join(File.dirname(__FILE__), '..' ) ) TemplateDir = "#{MVTestDir}/tmp/template" TemplateErbDir = "#{MVTestDir}/tmp/erb" FileMIOTemplatePathname = Pathname.new(TemplateDir) FileMIOTemplateDefaultExtension = '.html' ErbPathname = Pathname.new(TemplateErbDir) ErbDefaultExtension = '.rhtml' CatDogPath = 'cat/dog.html' # HelloWorldFullPath = "#{TemplateDir}/hello_world.txt" HelloWorldPath = 'hello_world.txt' # TestWritePath = 'foo.txt' # TestWriteFullPath = "#{TemplateDir}/foo.txt" # TestWritePathname = Pathname.new(TestWriteFullPath) def setup @mio = MIOTrees.new @mio.foo = FileMIOTree.new(FileMIOTemplatePathname, ErbDefaultExtension) #??just use TemplateDir?? @mio.bar = FileMIOTree.new(ErbPathname, ErbDefaultExtension) #??just use TemplateErbDir?? @mio.baz = StringHashMIOTree.new @mio.msh = MTimeStringHashMIOTree.new @mio.rec = RailsErbCacheMIOTree.new end def test_mio_setup assert_kind_of(FileMIOTree, @mio.foo) assert_kind_of(FileMIOTree, @mio.bar) assert_kind_of(StringHashMIOTree, @mio.baz) assert_kind_of(MTimeStringHashMIOTree, @mio.msh) assert_kind_of(RailsErbCacheMIOTree, @mio.rec) assert_nil(@mio.not_there) assert_equal(FileMIOTemplatePathname.to_s, @mio.foo.to_s) assert_equal(ErbPathname.to_s, @mio.bar.to_s) end def test_mio_filemiotree_interface assert(@mio.foo.respond_to?(:path)) assert(@mio.foo.respond_to?(:find)) assert(@mio.foo.respond_to?(:cleanup_path_get_relative_pathname)) end def test_mio_stringmiotree_interface assert(@mio.baz.respond_to?(:path)) assert(@mio.baz.respond_to?(:find)) assert(@mio.baz.respond_to?(:cleanup_path_get_relative_pathname)) end def test_mio_mtime_stringmiotree_interface assert(@mio.msh.respond_to?(:path)) assert(@mio.msh.respond_to?(:find)) assert(@mio.msh.respond_to?(:cleanup_path_get_relative_pathname)) end def test_mio_rec_miotree_interface assert(@mio.rec.respond_to?(:path)) assert(@mio.rec.respond_to?(:find)) assert(@mio.rec.respond_to?(:cleanup_path_get_relative_pathname)) end def test_mio_filemio_interface assert(@mio.foo.path(CatDogPath).respond_to?(:pathname)) assert(@mio.foo.path(CatDogPath).respond_to?(:full_pathname)) assert(@mio.foo.path(CatDogPath).respond_to?(:read)) assert(@mio.foo.path(CatDogPath).respond_to?(:write)) assert(@mio.foo.path(CatDogPath).respond_to?(:exist?)) assert(@mio.foo.path(CatDogPath).respond_to?(:identical?)) assert(@mio.foo.path(CatDogPath).respond_to?(:mtime)) end def test_mio_stringmio_interface assert(@mio.baz.path(CatDogPath).respond_to?(:pathname)) assert(@mio.baz.path(CatDogPath).respond_to?(:full_pathname)) assert(@mio.baz.path(CatDogPath).respond_to?(:read)) assert(@mio.baz.path(CatDogPath).respond_to?(:write)) assert(@mio.baz.path(CatDogPath).respond_to?(:exist?)) assert(@mio.baz.path(CatDogPath).respond_to?(:identical?)) assert(@mio.baz.path(CatDogPath).respond_to?(:mtime)) end def test_mio_mtime_stringmio_interface assert(@mio.msh.path(CatDogPath).respond_to?(:pathname)) assert(@mio.msh.path(CatDogPath).respond_to?(:full_pathname)) assert(@mio.msh.path(CatDogPath).respond_to?(:read)) assert(@mio.msh.path(CatDogPath).respond_to?(:write)) assert(@mio.msh.path(CatDogPath).respond_to?(:exist?)) assert(@mio.msh.path(CatDogPath).respond_to?(:identical?)) assert(@mio.msh.path(CatDogPath).respond_to?(:mtime)) end def test_mio_rec_mio_interface assert(@mio.rec.path(CatDogPath).respond_to?(:pathname)) assert(@mio.rec.path(CatDogPath).respond_to?(:full_pathname)) assert(@mio.rec.path(CatDogPath).respond_to?(:read)) assert(@mio.rec.path(CatDogPath).respond_to?(:write)) assert(@mio.rec.path(CatDogPath).respond_to?(:exist?)) assert(@mio.rec.path(CatDogPath).respond_to?(:identical?)) assert(@mio.rec.path(CatDogPath).respond_to?(:mtime)) end end