2011-05-11 03:44:02 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2010-09-12 17:09:10 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
require 'coffee-script'
|
2011-04-11 06:46:21 -04:00
|
|
|
require 'execjs'
|
|
|
|
|
|
|
|
begin
|
|
|
|
ExecJS.compile '1'
|
|
|
|
rescue Exception
|
|
|
|
raise LoadError, 'unable to execute JavaScript'
|
|
|
|
end
|
2010-09-12 17:09:10 -04:00
|
|
|
|
|
|
|
class CoffeeTest < Test::Unit::TestCase
|
2010-09-19 11:57:48 -04:00
|
|
|
def coffee_app(options = {}, &block)
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app do
|
2010-09-12 17:09:10 -04:00
|
|
|
set :views, File.dirname(__FILE__) + '/views'
|
2010-09-19 11:57:48 -04:00
|
|
|
set(options)
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/', &block)
|
|
|
|
end
|
2010-09-12 17:09:10 -04:00
|
|
|
get '/'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders inline Coffee strings' do
|
|
|
|
coffee_app { coffee "alert 'Aye!'\n" }
|
|
|
|
assert ok?
|
2011-04-13 08:53:40 -04:00
|
|
|
assert body.include?("alert('Aye!');")
|
2010-09-12 17:09:10 -04:00
|
|
|
end
|
|
|
|
|
2010-09-19 11:57:48 -04:00
|
|
|
it 'defaults content type to javascript' do
|
|
|
|
coffee_app { coffee "alert 'Aye!'\n" }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "application/javascript;charset=utf-8", response['Content-Type']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults allows setting content type per route' do
|
|
|
|
coffee_app do
|
|
|
|
content_type :html
|
|
|
|
coffee "alert 'Aye!'\n"
|
|
|
|
end
|
|
|
|
assert ok?
|
|
|
|
assert_equal "text/html;charset=utf-8", response['Content-Type']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults allows setting content type globally' do
|
|
|
|
coffee_app(:coffee => { :content_type => 'html' }) do
|
|
|
|
coffee "alert 'Aye!'\n"
|
|
|
|
end
|
|
|
|
assert ok?
|
|
|
|
assert_equal "text/html;charset=utf-8", response['Content-Type']
|
|
|
|
end
|
|
|
|
|
2010-09-12 17:09:10 -04:00
|
|
|
it 'renders .coffee files in views path' do
|
|
|
|
coffee_app { coffee :hello }
|
|
|
|
assert ok?
|
2011-04-13 08:53:40 -04:00
|
|
|
assert_include body, "alert(\"Aye!\");"
|
2010-09-12 17:09:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores the layout option' do
|
|
|
|
coffee_app { coffee :hello, :layout => :layout2 }
|
|
|
|
assert ok?
|
2011-04-13 08:53:40 -04:00
|
|
|
assert_include body, "alert(\"Aye!\");"
|
2010-09-12 17:09:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises error if template not found" do
|
|
|
|
mock_app {
|
|
|
|
get('/') { coffee :no_such_template }
|
|
|
|
}
|
2011-04-13 08:56:37 -04:00
|
|
|
assert_raise(Errno::ENOENT) { get('/') }
|
2010-09-12 17:09:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "passes coffee options to the coffee engine" do
|
2011-04-13 08:53:40 -04:00
|
|
|
coffee_app { coffee "alert 'Aye!'\n", :no_wrap => true }
|
2010-09-12 17:09:10 -04:00
|
|
|
assert ok?
|
2011-11-09 13:05:51 -05:00
|
|
|
assert_body "alert('Aye!');"
|
2010-09-12 17:09:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "passes default coffee options to the coffee engine" do
|
2011-04-13 08:53:40 -04:00
|
|
|
mock_app do
|
2010-09-12 17:09:10 -04:00
|
|
|
set :coffee, :no_wrap => true # default coffee style is :nested
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/') { coffee "alert 'Aye!'\n" }
|
2011-04-13 08:53:40 -04:00
|
|
|
end
|
2010-09-12 17:09:10 -04:00
|
|
|
get '/'
|
|
|
|
assert ok?
|
2011-11-09 13:05:51 -05:00
|
|
|
assert_body "alert('Aye!');"
|
2010-09-12 17:09:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-25 03:27:15 -05:00
|
|
|
rescue LoadError
|
2010-09-12 17:09:10 -04:00
|
|
|
warn "#{$!.to_s}: skipping coffee tests"
|
|
|
|
end
|