Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 63 lines (45 sloc) 1.472 kb
5d5467a @zzak init
zzak authored
1 Test::Unit
2 ----------
3
4 One of the advantages of using
5 [Test::Unit](http://rdoc.info/gems/test-unit/2.1.2/frames) is that it already
6 ships with Ruby **1.8.7** and you can skip the installation part in some cases.
7
8 Set up rack-test by including `Rack::Test::Methods` into your test class and
9 defining `app`:
10
11 ENV['RACK_ENV'] = 'test'
12 require 'test/unit'
13 require 'rack/test'
14
15 begin
16 require_relative 'my-app.rb'
17 rescue NameError
18 require File.expand_path('my-app.rb', __FILE__)
19 end
20
21 class HomepageTest < Test::Unit::TestCase
22 include Rack::Test:Methods
23 def app() Sinatra::Application end
24
25 def test_homepage
26 get '/'
27 assert last_response.ok?
28 end
29 end
30
31 Since [Contest][ct] and [Test::Spec][ts] are both extensions for Test::Unit,
32 all you have to do is install them and add a `require 'contest'` or `require
33 'test/spec'` to your test helper.
34
35 **Shoulda**
36
37 begin
38 require_relative 'test_helper'
39 rescue NameError
40 require File.expand_path('test_helper', __FILE__)
41 end
42
43 class ExampleUnitTest < Test::Unit::TestCase
44
45 include Rack::Test::Methods
46
47 def app() Sinatra::Application end
48
49 context "view my page" do
50 setup do
51 get '/'
52 end
53
54 should "greet the visitor" do
55 assert last_response.ok?
56 assert_equal 'Welcome to my page!', last_response.body
57 end
58
59 end
60 end
61
62
Something went wrong with that request. Please try again.