require File.dirname(__FILE__) + '/spec_helper'
describe Frank::Compile do
include Rack::Test::Methods
include Frank::Spec::Helpers
let(:proj_dir) { File.join(File.dirname(__FILE__), 'template') }
context 'default output' do
context 'without specifying an export dir' do
after do
FileUtils.rm_r File.join(proj_dir, Frank.export.path)
end
it 'creates the default export dir' do
Frank.bootstrap(proj_dir)
Dir.chdir proj_dir do
frank 'export'
File.directory?(Frank.export.path).should be_true
end
end
end
context 'specifying an export dir' do
let(:output_dir) { File.join(proj_dir, 'output') }
before(:all) do
Dir.chdir proj_dir do
frank 'export', output_dir
end
end
after(:all) do
FileUtils.rm_r output_dir
end
it 'creates the output folder' do
File.exist?(File.join(File.dirname(__FILE__), 'template/output')).should be_true
end
it 'creates index.html' do
output = File.join(File.dirname(__FILE__), 'template/output/index.html')
File.read(output).should == "\n
/
\n\n
hello worlds
\n /
\n\n"
end
it 'creates partial_test.html' do
output = File.join(File.dirname(__FILE__), 'template/output/partial_test.html')
File.read(output).should == "\n/partial_test
\n\n
hello worlds
\n
/partial_test
\n
hello from partial
\n
\n"
end
it 'creates partial_locals_test.html' do
output = File.join(File.dirname(__FILE__), 'template/output/partial_locals_test.html')
File.read(output).should == "\n/partial_locals_test
\n\n
hello worlds
\n
/partial_locals_test
\n
hello from local
\n
\n"
end
it 'creates child.html' do
output = File.join(File.dirname(__FILE__), 'template/output/nested/child.html')
File.read(output).should == "\n
hello from child
\n\n"
end
it 'creates deep.html' do
output = File.join(File.dirname(__FILE__), 'template/output/nested/deeper/deep.html')
File.read(output).should == "\n
really deep
\n\n"
end
it 'creates no_layout.html' do
output = File.join(File.dirname(__FILE__), 'template/output/no_layout.html')
File.read(output).should == "i have no layout
\n"
end
it 'creates coffee.js' do
output = File.join(File.dirname(__FILE__), 'template/output/coffee.js')
File.read(output).should == "(function() {\n ({\n greeting: \"Hello CoffeeScript\"\n });\n}).call(this);\n"
end
it 'creates erb.html' do
output = File.join(File.dirname(__FILE__), 'template/output/erb.html')
File.read(output).should == "\n/erb
\n\n
hello worlds
\n\n"
end
it 'creates redcloth.html' do
output = File.join(File.dirname(__FILE__), 'template/output/redcloth.html')
File.read(output).should == "\n/redcloth
\n\n
hello worlds
\n\n"
end
it 'creates markdown.html' do
output = File.join(File.dirname(__FILE__), 'template/output/markdown.html')
File.read(output).should == "\n/markdown
\n\n
hello worlds
\n\n"
end
it 'creates liquid.html' do
output = File.join(File.dirname(__FILE__), 'template/output/liquid.html')
File.read(output).should == "\n/liquid
\n\n
hello worlds
\n\n"
end
it 'creates builder.html' do
output = File.join(File.dirname(__FILE__), 'template/output/builder.html')
File.read(output).should == "\n/builder
\n\n
hello worlds
\n\n"
end
it 'copies static.html' do
output = File.join(File.dirname(__FILE__), 'template/output/files/static.html')
File.read(output).should == "hello from static"
end
it "doesn't create partials" do
File.exist?(File.join(File.dirname(__FILE__), 'template/output/_partial.html')).should be_false
end
it 'handles lorem replacement fields' do
output = File.join(File.dirname(__FILE__), 'template/output/lorem_test.html')
File.read(output).should include("replace-this
")
File.read(output).should include("replace-this
")
File.read(output).should include("replace-this
")
File.read(output).should include("replace-this
")
File.read(output).should include("replace-this
")
File.read(output).should include("replace-this
")
File.read(output).should include("")
end
it 'should not render the refresh js' do
output = File.join(File.dirname(__FILE__), 'template/output/refresh.html')
File.read(output).should == "\n/refresh
\n\n \n
\n"
end
end
end
context 'productions output' do
let(:output_dir) { File.join(proj_dir, 'output') }
before :all do
Dir.chdir proj_dir do
frank 'export', output_dir, '--production'
end
end
after(:all) do
FileUtils.rm_r output_dir
end
it 'creates the output folder' do
File.exist?(File.join(File.dirname(__FILE__), 'template/output')).should be_true
end
it 'creates index.html' do
output = File.join(File.dirname(__FILE__), 'template/output/index.html')
File.read(output).should == "\n/
\n\n
hello worlds
\n /
\n\n"
end
it 'creates partial_test.html' do
output = File.join(File.dirname(__FILE__), 'template/output/partial_test/index.html')
File.read(output).should == "\n/partial_test
\n\n
hello worlds
\n
/partial_test
\n
hello from partial
\n
\n"
end
it 'creates partial_locals_test.html' do
output = File.join(File.dirname(__FILE__), 'template/output/partial_locals_test/index.html')
File.read(output).should == "\n/partial_locals_test
\n\n
hello worlds
\n
/partial_locals_test
\n
hello from local
\n
\n"
end
it 'creates child.html' do
output = File.join(File.dirname(__FILE__), 'template/output/nested/child/index.html')
File.read(output).should == "\n
hello from child
\n\n"
end
it 'creates deep.html' do
output = File.join(File.dirname(__FILE__), 'template/output/nested/deeper/deep/index.html')
File.read(output).should == "\n
really deep
\n\n"
end
it 'creates no_layout.html' do
output = File.join(File.dirname(__FILE__), 'template/output/no_layout/index.html')
File.read(output).should == "i have no layout
\n"
end
it 'creates coffee.js' do
output = File.join(File.dirname(__FILE__), 'template/output/coffee.js')
File.read(output).should == "(function() {\n ({\n greeting: \"Hello CoffeeScript\"\n });\n}).call(this);\n"
end
it 'creates erb.html' do
output = File.join(File.dirname(__FILE__), 'template/output/erb/index.html')
File.read(output).should == "\n/erb
\n\n
hello worlds
\n\n"
end
it 'creates redcloth.html' do
output = File.join(File.dirname(__FILE__), 'template/output/redcloth/index.html')
File.read(output).should == "\n/redcloth
\n\n
hello worlds
\n\n"
end
it 'creates markdown.html' do
output = File.join(File.dirname(__FILE__), 'template/output/markdown/index.html')
File.read(output).should == "\n/markdown
\n\n
hello worlds
\n\n"
end
it 'creates liquid.html' do
output = File.join(File.dirname(__FILE__), 'template/output/liquid/index.html')
File.read(output).should == "\n/liquid
\n\n
hello worlds
\n\n"
end
it 'creates builder.html' do
output = File.join(File.dirname(__FILE__), 'template/output/builder/index.html')
File.read(output).should == "\n/builder
\n\n
hello worlds
\n\n"
end
it 'copies static.html' do
output = File.join(File.dirname(__FILE__), 'template/output/files/static.html')
File.read(output).should == "hello from static"
end
it "doesn't create partials" do
File.exist?(File.join(File.dirname(__FILE__), 'template/output/_partial/index.html')).should be_false
end
it 'handles lorem replacement fields' do
output = File.join(File.dirname(__FILE__), 'template/output/lorem_test/index.html')
File.read(output).should include("replace-this
")
File.read(output).should include("replace-this
")
File.read(output).should include("replace-this
")
File.read(output).should include("replace-this
")
File.read(output).should include("replace-this
")
File.read(output).should include("replace-this
")
File.read(output).should include("")
end
it 'should not render the refresh js' do
output = File.join(File.dirname(__FILE__), 'template/output/refresh/index.html')
File.read(output).should == "\n/refresh
\n\n \n
\n"
end
end
end