Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tannerburson/111268 to your computer and use it in GitHub Desktop.
Save tannerburson/111268 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
gem 'rack', '=0.9.1'
gem 'thin', '=1.0.0'
require 'sinatra/base'
## To run this just run thin -R config.ru start
## The default tests pass, allowing the app to start. If the tests failed, the app would not even attempt to start.
##
## Wrap up our sample app in a class, this let's us keep the entire app
## in the rackup file.
class SinatrAll < Sinatra::Base
set :app_file, __FILE__
set :root, File.dirname(__FILE__)
set :server, 'thin'
get '/' do
content_type 'text/plain'
'Hello World'
end
end
# Run me with 'spec' executable to run my specs!
if $0 =~ /spec$/
require 'spec/interop/test'
require 'sinatra/test'
describe "Example App" do
include Sinatra::Test
before { @app = SinatrAll }
it "should serve a greeting" do
get '/'
response.should be_ok
response.body.should == "Hello, world"
end
it "should serve content as text/plain" do
get '/'
response.headers['Content-Type'].should == 'text/plain'
end
end
elsif system("spec " + __FILE__) && 0 == $?
## Here we run the specs and check for a 0 exit status.
run SinatrAll ## Only run if we passed the specs
else
exit 1 ## This keeps thin from choking
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment