diff --git a/test/sinatra_app.rb b/test/sinatra_app.rb new file mode 100644 index 0000000..ae3bd4d --- /dev/null +++ b/test/sinatra_app.rb @@ -0,0 +1,13 @@ +require 'rubygems' + +require 'sinatra' +require 'sinatra/url_for' + +get "/" do + content_type "text/plain" + <<"EOD" +#{url_for("/")} +#{url_for("/foo")} +#{url_for("/foo", :full)} +EOD +end diff --git a/test/sinatra_static_assets_test.rb b/test/sinatra_static_assets_test.rb index a9444ce..2814be6 100644 --- a/test/sinatra_static_assets_test.rb +++ b/test/sinatra_static_assets_test.rb @@ -1,91 +1,24 @@ -require File.dirname(__FILE__) + '/test_helper' +require 'sinatra_app' +require 'test/unit' +require 'rack/test' -class SinatraRDiscountTest < Test::Unit::TestCase +set :environment, :test + +class SintraStaticAssetsTest < Test::Unit::TestCase include Rack::Test::Methods - - def rdiscount_app(&block) - mock_app { - set :views, File.dirname(__FILE__) + '/views' - helpers Sinatra::RDiscount - set :show_exceptions, false - get '/', &block - } - get '/' - end - - def test_renders_inline_strings - rdiscount_app { rdiscount 'hello world' } - assert last_response.ok? - assert_equal "

hello world

\n", last_response.body - end - - def test_renders_inline_erb_string - rdiscount_app { rdiscount '{%= 1 + 1 %}' } - assert last_response.ok? - assert_equal "

2

\n", last_response.body + + def app + Sinatra::Application end - def test_renders_files_in_views_path - rdiscount_app { rdiscount :hello } - assert last_response.ok? - assert_equal "

hello world

\n", last_response.body - end - - def test_takes_locals_option - rdiscount_app { - locals = {:foo => 'Bar'} - rdiscount "{%= foo %}", :locals => locals - } - assert last_response.ok? - assert_equal "

Bar

\n", last_response.body - end - - def test_renders_with_inline_layouts - rdiscount_app { - rdiscount 'Sparta', :layout => 'THIS. IS. <%= yield.upcase %>' - } - assert last_response.ok? - assert_equal "THIS. IS.

SPARTA

\n", last_response.body - end - - def test_renders_with_file_layouts - rdiscount_app { - rdiscount 'hello world', :layout => :layout2 - } - assert last_response.ok? - assert_equal "erb layout\n

hello world

\n\n", last_response.body - end - - def test_renders_erb_with_blocks - mock_app { - set :views, File.dirname(__FILE__) + '/views' - helpers Sinatra::RDiscount - - def container - yield - end - def is; - "THIS. IS. SPARTA!" - end - - get '/' do - rdiscount '{% container do %} {%= is %} {% end %}' - end - } - + def test_it_says_hello_world get '/' assert last_response.ok? - assert_equal "

THIS. IS. SPARTA!

\n", last_response.body + assert_equal 'Hello World', last_response.body end - - def test_raises_error_if_template_not_found - mock_app { - set :views, File.dirname(__FILE__) + '/views' - helpers Sinatra::RDiscount - set :show_exceptions, false - - get('/') { rdiscount :no_such_template } - } - assert_raise(Errno::ENOENT) { get('/') } + + def test_it_says_hello_to_a_person + get '/', :name => 'Simon' + assert last_response.body.include?('Simon') end end diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 87487c0..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rubygems' -require 'test/unit' -require 'rack/test' - -$LOAD_PATH.unshift(File.dirname(__FILE__)) -require 'sinatra/rdiscount' - -require 'rdiscount' - -class Test::Unit::TestCase - include Rack::Test::Methods - - attr_reader :app - - # Sets up a Sinatra::Base subclass defined with the block - # given. Used in setup or individual spec methods to establish - # the application. - def mock_app(base=Sinatra::Base, &block) - @app = Sinatra.new(base, &block) - end -end