Created
November 15, 2008 19:10
-
-
Save lifo/25300 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$: << "/Users/lifo/Rails/sinatra/lib" | |
require 'rubygems' | |
require 'sinatra' | |
require 'sinatra/test/unit' | |
require 'app' | |
class Rack::Response | |
attr_accessor :variables | |
end | |
class Rack::MockResponse | |
attr_accessor :variables | |
def initialize_with_variables(status, headers, body, errors=StringIO.new("")) | |
self.variables = body.variables if body.respond_to?(:variables=) | |
initialize_without_variables(status, headers, body, errors) | |
end | |
alias_method :initialize_without_variables, :initialize | |
alias_method :initialize, :initialize_with_variables | |
def assigns(name) | |
variables["@#{name}"] | |
end | |
end | |
class Sinatra::EventContext | |
def finish | |
result = super | |
self.response.variables = {} | |
instance_variables.each do |var| | |
self.response.variables[var] = instance_variable_get(var) | |
end | |
result | |
end | |
end | |
class AppTest < Test::Unit::TestCase | |
def test_my_default | |
get_it '/' | |
assert_equal 'Hello Templates', @response.body | |
assert_equal 1, @response.assigns(:hello) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment