added tests

This commit is contained in:
Wlodek Bzyl 2009-07-05 18:28:12 +02:00
parent 4e679f85a3
commit 1a58c0806b
3 changed files with 32 additions and 9 deletions

View File

@ -20,7 +20,7 @@ This Sinatra extensions provides following helper methods:
gemspec.files = %w{TODO VERSION.yml} + FileList['lib/**/*.rb', 'test/**/*.rb', 'examples/**/*'] gemspec.files = %w{TODO VERSION.yml} + FileList['lib/**/*.rb', 'test/**/*.rb', 'examples/**/*']
gemspec.add_runtime_dependency 'rack', '>=1.0.0' gemspec.add_runtime_dependency 'rack', '>=1.0.0'
gemspec.add_runtime_dependency 'sinatra' gemspec.add_runtime_dependency 'sinatra', '>=0.9.1'
gemspec.add_runtime_dependency 'emk-sinatra-url-for', '>=0.2.1' gemspec.add_runtime_dependency 'emk-sinatra-url-for', '>=0.2.1'
gemspec.add_development_dependency 'rack-test', '>=0.3.0' gemspec.add_development_dependency 'rack-test', '>=0.3.0'

View File

@ -2,8 +2,9 @@ require 'rubygems'
require 'sinatra' require 'sinatra'
require 'sinatra/url_for' require 'sinatra/url_for'
require 'sinatra/static_assets'
get "/" do get "/url_for" do
content_type "text/plain" content_type "text/plain"
<<"EOD" <<"EOD"
#{url_for("/")} #{url_for("/")}
@ -11,3 +12,10 @@ get "/" do
#{url_for("/foo", :full)} #{url_for("/foo", :full)}
EOD EOD
end end
get "/image_tag" do
content_type "text/plain"
<<"EOD"
#{image_tag("/images/foo.jpg", :alt => "[foo image]")}
EOD
end

View File

@ -11,14 +11,29 @@ class SintraStaticAssetsTest < Test::Unit::TestCase
Sinatra::Application Sinatra::Application
end end
def test_it_says_hello_world def test_url_for_returns_absolute_paths_and_full_urls
get '/' get '/url_for', {}, 'SCRIPT_NAME' => '/bar'
assert last_response.ok? assert last_response.ok?
assert_equal 'Hello World', last_response.body assert_equal last_response.body, <<EOD
/bar/
/bar/foo
http://example.org/bar/foo
EOD
end end
def test_it_says_hello_to_a_person def test_image_tag_returns_absolute_paths_and_full_urls
get '/', :name => 'Simon' get '/image_tag', {}, 'SCRIPT_NAME' => '/bar'
assert last_response.body.include?('Simon') assert last_response.ok?
assert_equal last_response.body, <<EOD
<img alt="[foo image]" src="/bar/images/foo.jpg">
EOD
end end
end end
__END__
stylesheet_link_tag "/stylesheets/screen.css", "/stylesheets/summer.css", :media => "projection"
javascript_script_tag "/javascripts/jquery.js", "/javascripts/summer.js", :charset => "iso-8859-2"
link_to "Tatry Mountains Rescue Team", "/topr"