sheatsb (owner)

Revisions

gist: 112608 Download_button fork
public
Public Clone URL: git://gist.github.com/112608.git
Embed All Files: show embed
sinatra-tests-baked-in.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/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