sinatra-static-assets/test/sinatra_static_assets_test.rb

58 lines
1.6 KiB
Ruby
Raw Normal View History

2009-07-05 16:00:34 +00:00
require 'sinatra_app'
require 'test/unit'
require 'rack/test'
2009-06-01 17:53:37 +00:00
2009-07-05 16:00:34 +00:00
set :environment, :test
2009-06-01 17:53:37 +00:00
2009-07-05 16:00:34 +00:00
class SintraStaticAssetsTest < Test::Unit::TestCase
include Rack::Test::Methods
2009-06-01 17:53:37 +00:00
2009-07-05 16:00:34 +00:00
def app
Sinatra::Application
2009-06-01 17:53:37 +00:00
end
2009-07-05 16:28:12 +00:00
def test_url_for_returns_absolute_paths_and_full_urls
get '/url_for', {}, 'SCRIPT_NAME' => '/bar'
2009-06-01 17:53:37 +00:00
assert last_response.ok?
2009-07-05 16:28:12 +00:00
assert_equal last_response.body, <<EOD
/bar/
/bar/foo
http://example.org/bar/foo
EOD
2009-06-01 17:53:37 +00:00
end
2009-07-05 16:28:12 +00:00
2009-07-06 21:02:42 +00:00
def test_image_tag_returns_sub_uri
2009-07-05 16:28:12 +00:00
get '/image_tag', {}, 'SCRIPT_NAME' => '/bar'
assert last_response.ok?
assert_equal last_response.body, <<EOD
2009-11-23 21:07:57 +00:00
<img alt="[foo image]" src="/bar/images/foo.jpg">
2009-07-05 16:28:12 +00:00
EOD
2009-06-01 17:53:37 +00:00
end
2009-07-05 16:28:12 +00:00
2009-07-06 21:02:42 +00:00
def test_stylesheet_link_tag_returns_sub_uri
get '/stylesheet_link_tag', {}, 'SCRIPT_NAME' => '/bar'
assert last_response.ok?
assert_equal last_response.body, <<EOD
2009-11-23 21:07:57 +00:00
<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">
2009-07-06 21:02:42 +00:00
EOD
end
def test_javascript_script_tag_returns_sub_uri
get '/javascript_script_tag', {}, 'SCRIPT_NAME' => '/bar'
assert last_response.ok?
assert_equal last_response.body, <<EOD
<script charset="iso-8859-2" src="/bar/javascripts/summer.js" type="text/javascript"></script>
EOD
end
def test_link_to_tag_returns_sub_uri
get '/link_to_tag', {}, 'SCRIPT_NAME' => '/bar'
assert last_response.ok?
assert_equal last_response.body, <<EOD
<a href="/bar/topr">Tatry Mountains Rescue Team</a>
2009-07-06 21:02:42 +00:00
EOD
end
2009-07-05 16:28:12 +00:00
2009-06-01 17:53:37 +00:00
end