test/test_vitrine.rb in vitrine-0.0.11 vs test/test_vitrine.rb in vitrine-0.0.12
- old
+ new
@@ -1,31 +1,10 @@
require 'helper'
class TestVitrine < Test::Unit::TestCase
- include Rack::Test::Methods
+ include Rack::Test::Methods, VitrineTesting
- # Wrap the test run in mktimpdir where we will store our temp application
- def run(runner)
- Dir.mktmpdir("vitrine-tests") do | dir_path |
- @tempdir = dir_path
- super
- end
- end
-
- def write_public(name)
- FileUtils.mkdir_p @tempdir + '/public'
- File.open(File.join(@tempdir, 'public', name), 'w') do | f |
- yield f
- end
- end
-
- def app
- vitrine = Vitrine::App.new
- vitrine.settings.set :root, @tempdir
- vitrine
- end
-
def test_fetch_index_without_index_should_404
get '/'
assert_equal 404, last_response.status, "Should have responded with 404 since there is no template"
end
@@ -70,19 +49,19 @@
get '/'
assert last_response.ok?, "Should have fetched the index.html"
end
-# def test_fetches_index_in_subdirectory_if_present
-# write_public 'items/index.html' do | f |
-# f.write 'this just in'
-# end
-#
-# get '/items'
-# assert last_response.ok?, "Should have responded with 404 since there is no template"
-# assert_equal 'this just in', last_response.body
-# end
+ def test_fetches_index_in_subdirectory_if_present
+ write_public 'items/index.html' do | f |
+ f.write 'this just in'
+ end
+
+ get '/items'
+ assert last_response.ok?, "Should have responded with 404 since there is no template"
+ assert_equal 'this just in', last_response.body
+ end
def test_passes_coffeescript_as_raw_file
write_public 'nice.coffee' do | f |
f.write 'alert "rockage!"'
end
@@ -104,9 +83,27 @@
assert_equal 'text/javascript;charset=utf-8', last_response.content_type
assert last_response.body.include?( 'alert("rockage!")'), 'Should include the compiled function'
assert last_response.body.include?( '//# sourceMappingURL=/nice.js.map'),
'Should include the reference to the source map'
+ end
+
+ def test_compiles_coffeescript_sourcemap
+
+ FileUtils.mkdir_p File.join(@tempdir, 'public', 'js')
+
+ write_public 'js/nice.coffee' do | f |
+ f.puts 'alert "rockage!"'
+ end
+
+ # Sourcemap will only ever get requested AFTER the corresponding JS file
+ get '/js/nice.js'
+ assert last_response.ok?
+
+ get '/js/nice.js.map'
+ ref = {"version"=>3, "file"=>"", "sourceRoot"=>"", "sources"=>["/js/nice.coffee"],
+ "names"=>[], "mappings"=>"AAAA;CAAA,CAAA,GAAA,KAAA;CAAA"}
+ assert_equal ref, JSON.parse(last_response.body)
end
def test_sends_vanilla_js_if_its_present
write_public 'vanilla.js' do | f |
f.puts 'vanilla();'