Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 88 lines (63 sloc) 1.741 kb
78cbc0e @dashdotat Bootstrapping of changes to doc for testing
dashdotat authored
1 ---
2 title: Testing Sinatra
3 layout: default
4 ---
5
6 ## Testing
7
8 The Sinatra::Test module includes a variety of helper methods for testing
9 your Sinatra app. Sinatra includes support for Test::Unit, test-spec,
10 RSpec, and Bacon through separate source files.
11
12 ### Test::Unit
13 require 'sinatra'
14 require 'sinatra/test/unit'
15 require 'my_sinatra_app'
16
17 class MyAppTest < Test::Unit::TestCase
18 def test_my_default
19 get '/'
20 assert_equal 'My Default Page!', @response.body
21 end
22
23 def test_with_agent
24 get '/', :env => { :agent => 'Songbird' }
25 assert_equal 'You're in Songbird!', @response.body
26 end
27
28 ...
29
30 end
31
32 ### Test::Spec
33
34 Install the test-spec gem and require <tt>'sinatra/test/spec'</tt> before
35 your app:
36
37 require 'sinatra'
38 require 'sinatra/test/spec'
39 require 'my_sinatra_app'
40
41 describe 'My app' do
42 it 'should show a default page' do
43 get '/'
44 should.be.ok
45 body.should.equal 'My Default Page!'
46 end
47
48 ...
49
50 end
51
52 ### RSpec
53
54 Install the rspec gem and require <tt>'sinatra/test/rspec'</tt> before your
55 app:
56
57 require 'sinatra'
58 require 'sinatra/test/rspec'
59 require 'my_sinatra_app'
60
61 describe 'My app' do
62 it 'should show a default page' do
63 get '/'
64 @response.should be_ok
65 @response.body.should == 'My Default Page!'
66 end
67
68 ...
69
70 end
71
72 ### Bacon
73
74 require 'sinatra'
75 require 'sinatra/test/bacon'
76 require 'my_sinatra_app'
77
78 describe 'My app' do
79 it 'should be ok' do
80 get '/'
81 should.be.ok
82 body.should == 'Im OK'
83 end
84 end
85
86 See Sinatra::Test for more information on <tt>get</tt>, <tt>post</tt>, <tt>put</tt> and friends.
87
Something went wrong with that request. Please try again.