added more tests
This commit is contained in:
parent
48c1086562
commit
2ae1e750da
26
sinatra_baseapp.rb
Normal file
26
sinatra_baseapp.rb
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
path = File.expand_path("../lib" + File.dirname(__FILE__))
|
||||||
|
$:.unshift(path) unless $:.include?(path)
|
||||||
|
|
||||||
|
require 'rubygems'
|
||||||
|
require 'sinatra/base'
|
||||||
|
|
||||||
|
require 'sinatra/static_assets'
|
||||||
|
|
||||||
|
module Sinatra
|
||||||
|
class XHTML < Sinatra::Base
|
||||||
|
helpers Sinatra::UrlForHelper
|
||||||
|
register Sinatra::StaticAssets
|
||||||
|
|
||||||
|
enable :xhtml
|
||||||
|
|
||||||
|
get '/image_tag' do
|
||||||
|
content_type "text/plain"
|
||||||
|
"#{image_tag("/images/foo.jpg")}"
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/link_tag' do
|
||||||
|
content_type "text/plain"
|
||||||
|
"#{stylesheet_link_tag("/stylesheets/winter.css")}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
25
sinatra_static_assets_xhtml_test.rb
Normal file
25
sinatra_static_assets_xhtml_test.rb
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
require 'sinatra_baseapp'
|
||||||
|
require 'test/unit'
|
||||||
|
require 'rack/test'
|
||||||
|
|
||||||
|
class SintraStaticAssetsXHTMLTest < Test::Unit::TestCase
|
||||||
|
include Rack::Test::Methods
|
||||||
|
|
||||||
|
def app
|
||||||
|
Sinatra::XHTML.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_image_tag_closes
|
||||||
|
get '/image_tag'
|
||||||
|
assert last_response.ok?
|
||||||
|
assert_equal last_response.body, "<img src=\"/images/foo.jpg\"/>"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_link_tag_closes
|
||||||
|
get '/link_tag'
|
||||||
|
assert last_response.ok?
|
||||||
|
assert_equal last_response.body,
|
||||||
|
"<link charset=\"utf-8\" href=\"/stylesheets/winter.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\"/>"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -25,7 +25,7 @@ EOD
|
|||||||
get '/image_tag', {}, 'SCRIPT_NAME' => '/bar'
|
get '/image_tag', {}, 'SCRIPT_NAME' => '/bar'
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
assert_equal last_response.body, <<EOD
|
assert_equal last_response.body, <<EOD
|
||||||
<img alt="[foo image]" src="/bar/images/foo.jpg"/>
|
<img alt="[foo image]" src="/bar/images/foo.jpg">
|
||||||
EOD
|
EOD
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -33,8 +33,8 @@ EOD
|
|||||||
get '/stylesheet_link_tag', {}, 'SCRIPT_NAME' => '/bar'
|
get '/stylesheet_link_tag', {}, 'SCRIPT_NAME' => '/bar'
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
assert_equal last_response.body, <<EOD
|
assert_equal last_response.body, <<EOD
|
||||||
<link charset="utf-8" href="/bar/stylesheets/winter.css" media="projection" rel="stylesheet" type="text/css"/>
|
<link charset="utf-8" href="/bar/stylesheets/winter.css" media="projection" rel="stylesheet" type="text/css">
|
||||||
<link charset="utf-8" href="/bar/stylesheets/summer.css" media="projection" rel="stylesheet" type="text/css"/>
|
<link charset="utf-8" href="/bar/stylesheets/summer.css" media="projection" rel="stylesheet" type="text/css">
|
||||||
EOD
|
EOD
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user