Skip to content

Instantly share code, notes, and snippets.

@kematzy
Created June 9, 2009 10:11
Show Gist options
  • Select an option

  • Save kematzy/126403 to your computer and use it in GitHub Desktop.

Select an option

Save kematzy/126403 to your computer and use it in GitHub Desktop.
# demo/app.rb
# set the root of the whole app
::APP_ROOT = File.dirname(File.expand_path(__FILE__)) unless defined?(APP_ROOT)
class MyApp < Sinatra::Base
# snip set views etc
set :environment, ENV["RACK_ENV"] ||= 'test'
# configure do # optional
::DataMapper::Logger.new("#{APP_ROOT}/log/dm.admin.#{environment}.log", :debug)
::DataMapper.setup(:default, "sqlite3:#{APP_ROOT}/db/db.#{environment}.sqlite3")
::DataMapper.auto_upgrade!
# end
get '/' do
"Hello world!"
end
end
#===========================
# demo/test/test_helper.rb
require 'rubygems'
require 'test/spec'
require File.join(File.dirname(__FILE__), '..', 'app.rb')
require 'rack/test'
class Sinatra::Base
# Allow assertions in request context
include Test::Unit::Assertions
end
class Test::Unit::TestCase
# include Sinatra::Test
include Rack::Test::Methods
# this does nothing in the main app
# def setup
# Sinatra::Base.set :environment, :test
# end
def app
MyApp.new
end
end
#===========================
#demo/test/app_test.rb
require File.join(File.dirname(__FILE__) ,'test_helper.rb')
describe "App" do
before(:each) do
@app = MyApp
@new_app = @app.new
end
describe "#environment" do
it "should be set to :test" do
assert_equal('test', @app.environment)
end
end
describe "GET /" do
it "should get hello world" do
get('/')
assert_equal('Hello world!', last_response.body)
end
end #/GET /
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment