added tests
This commit is contained in:
parent
3eb2bb6683
commit
4e679f85a3
13
test/sinatra_app.rb
Normal file
13
test/sinatra_app.rb
Normal file
@ -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
|
@ -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
|
include Rack::Test::Methods
|
||||||
|
|
||||||
def rdiscount_app(&block)
|
def app
|
||||||
mock_app {
|
Sinatra::Application
|
||||||
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 "<p>hello world</p>\n", last_response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_renders_inline_erb_string
|
|
||||||
rdiscount_app { rdiscount '{%= 1 + 1 %}' }
|
|
||||||
assert last_response.ok?
|
|
||||||
assert_equal "<p>2</p>\n", last_response.body
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_renders_files_in_views_path
|
def test_it_says_hello_world
|
||||||
rdiscount_app { rdiscount :hello }
|
|
||||||
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 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 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 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::RDiscount
|
|
||||||
|
|
||||||
def container
|
|
||||||
yield
|
|
||||||
end
|
|
||||||
def is;
|
|
||||||
"THIS. IS. SPARTA!"
|
|
||||||
end
|
|
||||||
|
|
||||||
get '/' do
|
|
||||||
rdiscount '{% container do %} {%= is %} {% end %}'
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
get '/'
|
get '/'
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
assert_equal "<p> THIS. IS. SPARTA! </p>\n", last_response.body
|
assert_equal 'Hello World', last_response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_raises_error_if_template_not_found
|
def test_it_says_hello_to_a_person
|
||||||
mock_app {
|
get '/', :name => 'Simon'
|
||||||
set :views, File.dirname(__FILE__) + '/views'
|
assert last_response.body.include?('Simon')
|
||||||
helpers Sinatra::RDiscount
|
|
||||||
set :show_exceptions, false
|
|
||||||
|
|
||||||
get('/') { rdiscount :no_such_template }
|
|
||||||
}
|
|
||||||
assert_raise(Errno::ENOENT) { get('/') }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user