Skip to content

Commit

Permalink
use Rack::Test instead of Sinatra::Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wlodek Bzyl committed May 11, 2009
1 parent c782ca9 commit 7d0ae8e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
36 changes: 18 additions & 18 deletions test/sinatra_rdiscount_test.rb
@@ -1,12 +1,12 @@
require File.dirname(__FILE__) + '/test_helper'

class SinatraRDiscountTest < Test::Unit::TestCase
include Sinatra::Test
include Rack::Test::Methods

def rdiscount_app(&block)
mock_app {
set :views, File.dirname(__FILE__) + '/views'
helpers Sinatra::RDiscountTemplate
helpers Sinatra::RDiscount
set :show_exceptions, false
get '/', &block
}
Expand All @@ -15,51 +15,51 @@ def rdiscount_app(&block)

def test_renders_inline_strings
rdiscount_app { rdiscount 'hello world' }
assert ok?
assert_equal "<p>hello world</p>\n", body
assert last_response.ok?
assert_equal "<p>hello world</p>\n", last_response.body
end

def test_renders_inline_erb_string
rdiscount_app { rdiscount '{%= 1 + 1 %}' }
assert ok?
assert_equal "<p>2</p>\n", body
assert last_response.ok?
assert_equal "<p>2</p>\n", last_response.body
end

def test_renders_files_in_views_path
rdiscount_app { rdiscount :hello }
assert ok?
assert_equal "<h1>hello world</h1>\n", body
assert last_response.ok?
assert_equal "<h1>hello world</h1>\n", last_response.body
end

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

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

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

def test_renders_erb_with_blocks
mock_app {
set :views, File.dirname(__FILE__) + '/views'
helpers Sinatra::RDiscountTemplate
helpers Sinatra::RDiscount

def container
yield
Expand All @@ -74,14 +74,14 @@ def is;
}

get '/'
assert ok?
assert_equal "<p> THIS. IS. SPARTA! </p>\n", body
assert last_response.ok?
assert_equal "<p> THIS. IS. SPARTA! </p>\n", last_response.body
end

def test_raises_error_if_template_not_found
mock_app {
set :views, File.dirname(__FILE__) + '/views'
helpers Sinatra::RDiscountTemplate
helpers Sinatra::RDiscount
set :show_exceptions, false

get('/') { rdiscount :no_such_template }
Expand Down
6 changes: 4 additions & 2 deletions test/test_helper.rb
@@ -1,14 +1,16 @@
require 'rubygems'
require 'test/unit'
require 'sinatra/test'
require 'rack/test'

$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'sinatra/rdiscount'

require 'rdiscount'

class Test::Unit::TestCase
include Sinatra::Test
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
Expand Down

0 comments on commit 7d0ae8e

Please sign in to comment.