test/buildmaster/site/tc_site.rb in BuildMaster-0.8.1 vs test/buildmaster/site/tc_site.rb in BuildMaster-0.9.0
- old
+ new
@@ -1,43 +1,51 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "..", '..', "lib")
-require 'test/unit'
+require 'spec'
require 'buildmaster'
+require 'buildmaster/cotta'
+require 'buildmaster/cotta/in_memory_system'
module BuildMaster
-class SiteTest < Test::Unit::TestCase
- protected
- def setup
- super
- @temp = File.join(File.dirname(__FILE__), '..', '..', 'tmp')
-
- if (File.exist? @temp)
- delete_all(@temp)
- end
+context 'Site' do
+ setup do
+ @system = InMemorySystem.new
+ @cotta = Cotta.new(@system)
+ @root = @cotta.dir('site')
end
- private
- def delete_all(directory)
- Dir.foreach(directory) do |name|
- if (name != '.' && name != '..')
- file = File.join(directory, name)
- if (File.directory? file)
- delete_all(file)
- else
- File.delete(file)
- end
- end
- end
- Dir.rmdir(directory)
- end
-
- public
- def test_should_build_based_on_content
- spec = SiteSpec.new
- spec.output_dir = File.join(@temp, 'output')
- spec.content_dir = File.join(File.dirname(__FILE__), 'content')
+ specify 'should build base on content' do
+ content_dir = @root.dir('content')
+ content_dir.file('index.html').save(<<CONTENT
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <body><h1>Text</h1>
+ </body>
+</html>
+CONTENT
+)
+ content_dir.file('markdown.markdown').save(<<CONTENT
+--------------------
+markdown title
+--------------------
+Header
+===============
+CONTENT
+)
+ content_dir.file('textile.textile').save(<<CONTENT
+---------------------
+textile title
+---------------------
+h1. Header
+CONTENT
+)
+ spec = SiteSpec.new(nil, @cotta)
+ spec.output_dir = 'site/output'
+ spec.content_dir = 'site/content'
spec.template =<<TEMPLATE
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
<head>
<title>Title</title>
@@ -46,13 +54,29 @@
</body>
</html>
TEMPLATE
site = Site.new(spec)
site.build
- output_index = File.join(@temp, 'output', 'index.html')
- assert_equal(true, File.exist?(@temp), "#{@temp}")
- assert_equal(true, File.exist?(output_index), "#{output_index} exists")
+ expected_output_file = @root.dir('output').file('index.html')
+ @root.exists?.should_equal(true)
+ expected_output_file.exists?.should_equal(true)
+
end
-
+
+ specify 'ignore the svn and CVS directories' do
+ content_dir = @root.dir('content')
+ content_dir.dir('.svn').mkdirs
+ content_dir.dir('_svn').mkdirs
+ content_dir.dir('CVS').mkdirs
+ spec = SiteSpec.new(nil, @cotta)
+ spec.output_dir = 'site/output'
+ spec.content_dir = 'site/content'
+ spec.template = <<TEMPLATE
+<html/>
+TEMPLATE
+ site = Site.new(spec)
+ site.build
+ @root.dir('output').list.size.should_equal 0
+ end
end
end
\ No newline at end of file