test/buildmaster/tc_file_processor.rb in BuildMaster-0.8.1 vs test/buildmaster/tc_file_processor.rb in BuildMaster-0.9.0

- old
+ new

@@ -1,78 +1,102 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib") -require 'test/unit' +require 'spec' require 'rexml/document' require 'pathname' require 'buildmaster/file_processor' require 'buildmaster/xtemplate' +require 'buildmaster/cotta' +require 'buildmaster/cotta/in_memory_system' + module BuildMaster -class FileProcessorTest < Test::Unit::TestCase - def test_should_know_content_and_target + +context 'File Processor' do + setup do + @cotta = Cotta.new(InMemorySystem.new) + @cotta.file('content').save(<<CONTENT +line one +line two +line three +CONTENT +) + end + + teardown do + @cotta = nil + end + + specify 'should know content and target' do template = XTemplate.new(<<CONTENT <html xmlns="http://www.w3.org/1999/xhtml" xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0"> </html> CONTENT ) - site_spec = SiteSpec.new - current_dir = File.dirname(__FILE__) - site_spec.content_dir = File.join(current_dir, "content") - site_spec.output_dir = File.join(current_dir, "output") - processor = FileProcessor.new(template, File.join(current_dir, 'content', 'index.html'), site_spec) - assert_equal(File.join(current_dir, 'content', 'index.html'), processor.path_to_content_file) - assert_equal(true, processor.is_html?) + site_spec = SiteSpec.new('file.txt', @cotta) + site_spec.content_dir = 'content' + site_spec.output_dir = 'output' + processor = FileProcessor.new(template, @cotta.file('content/index.html'), site_spec) + processor.content_file.path.should_equal(Pathname.new('content/index.html')) + processor.is_html?.should_equal(true) end - def test_should_know_html_target + specify 'should know HTML target file' do template = XTemplate.new(<<CONTENT <html xmlns="http://www.w3.org/1999/xhtml" xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0"> </html> CONTENT ) - site_spec = SiteSpec.new - current_dir = File.dirname(__FILE__) - site_spec.content_dir = File.join(current_dir, "content") - site_spec.output_dir = File.join(current_dir, "output") - processor = FileProcessor.new(template, File.join(current_dir, 'content', 'index.gif'), site_spec) - assert_equal(File.join(current_dir, 'content', 'index.gif'), processor.path_to_content_file) - assert_equal(false, processor.is_html?) - assert_equal(nil, processor.generate_document) + site_spec = SiteSpec.new(nil, @cotta) + current_dir = @cotta.dir('root') + site_spec.content_dir = 'root/content' + site_spec.output_dir = 'root/output' + processor = FileProcessor.new(template, current_dir.dir('content').file('index.gif'), site_spec) + processor.content_file.path.should_equal current_dir.dir('content').file('index.gif').path + processor.is_html?.should_equal false + processor.generate_document.should_equal nil end - def test_should_load_from_target + specify 'should load from target file' do template_content = <<CONTENT <html xmlns="http://www.w3.org/1999/xhtml" xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0"> </html> CONTENT - site_spec = SiteSpec.new - current_dir = File.dirname(__FILE__) + site_spec = SiteSpec.new(__FILE__, @cotta) + current_dir = @cotta.dir(File.dirname(__FILE__)) + current_dir.dir('site').dir('content').file('index.html').save + current_dir.dir('site').dir('content').file('index.gif').save + current_dir.dir('site').dir('content').file('textile.textile').save + current_dir.dir('site').dir('content').file('markdown.markdown').save site_spec.template = template_content - site_spec.content_dir = File.join(current_dir, 'site', 'content') - site_spec.output_dir = File.join(current_dir, "output") + site_spec.content_dir = 'site/content' + site_spec.output_dir = 'output' processor = FileProcessor.for_request_path('/index.html', site_spec) - assert_equal(File.join(site_spec.content_dir, 'index.html'), processor.path_to_content_file) + processor.content_file.should_equal site_spec.content_dir.file('index.html') + processor = FileProcessor.for_request_path('/index.gif', site_spec) - assert_equal(File.join(site_spec.content_dir, 'index.gif'), processor.path_to_content_file) + processor.content_file.should_equal site_spec.content_dir.file('index.gif') + processor = FileProcessor.for_request_path('/textile.html', site_spec) - assert_equal(File.join(site_spec.content_dir, 'textile.textile'), processor.path_to_content_file) + processor.content_file.should_equal site_spec.content_dir.file('textile.textile') + processor = FileProcessor.for_request_path('/markdown.html', site_spec) - assert_equal(File.join(site_spec.content_dir, 'markdown.markdown'), processor.path_to_content_file) + processor.content_file.should_equal site_spec.content_dir.file('markdown.markdown') end def output_dir - return 'tmp' + return @cotta.dir('tmp') end def relative_to_root(path) return Pathname.new('tmp') end - - def test_mark_down_support + + specify 'should have support for markdown content' do template_content = <<CONTENT <html xmlns="http://www.w3.org/1999/xhtml" xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0"> <head><title><template:include elements="/html/head/title/text()"/></title></head> <body> @@ -81,21 +105,21 @@ </html> CONTENT hash = {'include' => Include.new(self)} template = XTemplate.new(template_content, hash) - processor = FileProcessor.new(template, "content_path", self) + processor = FileProcessor.new(template, @cotta.file('content_path'), self) markdown_content = <<CONTENT -------------------------------------------- Title Here -------------------------------------------- Header ===================== CONTENT document = processor.process_markdown(markdown_content) document = REXML::Document.new(document.to_s) - assert_equal('Title Here', REXML::XPath.first(document, '/html/head/title').text) - assert_equal('Header', REXML::XPath.first(document, '/html/body/h1').text) + REXML::XPath.first(document, '/html/head/title').text.should_equal 'Title Here' + REXML::XPath.first(document, '/html/body/h1').text.should_equal 'Header' end end end \ No newline at end of file