rtomayko-sinatra 0.9.0 → 0.9.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ require 'bacon'
2
+ require 'sinatra/test'
3
+
4
+ Sinatra::Default.set(
5
+ :environment => :test,
6
+ :run => false,
7
+ :raise_errors => true,
8
+ :logging => false
9
+ )
10
+
11
+ module Sinatra::Test
12
+ def should
13
+ @response.should
14
+ end
15
+ end
16
+
17
+ Bacon::Context.send(:include, Sinatra::Test)
@@ -1,2 +1,11 @@
1
1
  require 'sinatra/test'
2
+ require 'sinatra/test/unit'
3
+ require 'spec'
2
4
  require 'spec/interop/test'
5
+
6
+ Sinatra::Default.set(
7
+ :environment => :test,
8
+ :run => false,
9
+ :raise_errors => true,
10
+ :logging => false
11
+ )
@@ -1,2 +1,9 @@
1
1
  require 'test/spec'
2
2
  require 'sinatra/test'
3
+ require 'sinatra/test/unit'
4
+
5
+ module Sinatra::Test
6
+ def should
7
+ @response.should
8
+ end
9
+ end
@@ -1,10 +1,10 @@
1
- require 'test/unit'
2
1
  require 'sinatra/test'
2
+ require 'test/unit'
3
3
 
4
4
  Test::Unit::TestCase.send :include, Sinatra::Test
5
5
 
6
6
  Sinatra::Default.set(
7
- :env => :test,
7
+ :environment => :test,
8
8
  :run => false,
9
9
  :raise_errors => true,
10
10
  :logging => false
data/sinatra.gemspec CHANGED
@@ -3,17 +3,19 @@ Gem::Specification.new do |s|
3
3
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
4
 
5
5
  s.name = 'sinatra'
6
- s.version = '0.9.0'
7
- s.date = '2009-01-06'
6
+ s.version = '0.9.0.2'
7
+ s.date = '2009-01-18'
8
8
 
9
9
  s.description = "Classy web-development dressed in a DSL"
10
10
  s.summary = "Classy web-development dressed in a DSL"
11
11
 
12
12
  s.authors = ["Blake Mizerany"]
13
+ s.email = "sinatrarb@googlegroups.com"
13
14
 
14
15
  # = MANIFEST =
15
16
  s.files = %w[
16
- ChangeLog
17
+ AUTHORS
18
+ CHANGES
17
19
  LICENSE
18
20
  README.rdoc
19
21
  Rakefile
@@ -57,8 +59,8 @@ Gem::Specification.new do |s|
57
59
  lib/sinatra/images/404.png
58
60
  lib/sinatra/images/500.png
59
61
  lib/sinatra/main.rb
60
- lib/sinatra/rack/methodoverride.rb
61
62
  lib/sinatra/test.rb
63
+ lib/sinatra/test/bacon.rb
62
64
  lib/sinatra/test/rspec.rb
63
65
  lib/sinatra/test/spec.rb
64
66
  lib/sinatra/test/unit.rb
@@ -69,6 +71,7 @@ Gem::Specification.new do |s|
69
71
  test/erb_test.rb
70
72
  test/filter_test.rb
71
73
  test/haml_test.rb
74
+ test/helper.rb
72
75
  test/helpers_test.rb
73
76
  test/mapped_error_test.rb
74
77
  test/middleware_test.rb
@@ -96,7 +99,7 @@ Gem::Specification.new do |s|
96
99
  s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
97
100
 
98
101
  s.extra_rdoc_files = %w[README.rdoc LICENSE]
99
- s.add_dependency 'rack', '>= 0.9.0'
102
+ s.add_dependency 'rack', '>= 0.9.1'
100
103
 
101
104
  s.has_rdoc = true
102
105
  s.homepage = "http://sinatra.rubyforge.org"
data/test/base_test.rb CHANGED
@@ -1,12 +1,8 @@
1
- require 'test/spec'
2
- require 'sinatra/base'
3
- require 'sinatra/test'
1
+ require File.dirname(__FILE__) + '/helper'
4
2
 
5
3
  describe 'Sinatra::Base' do
6
- include Sinatra::Test
7
-
8
4
  it 'includes Rack::Utils' do
9
- Sinatra::Base.should.include Rack::Utils
5
+ assert Sinatra::Base.included_modules.include?(Rack::Utils)
10
6
  end
11
7
 
12
8
  it 'can be used as a Rack application' do
@@ -15,12 +11,12 @@ describe 'Sinatra::Base' do
15
11
  'Hello World'
16
12
  end
17
13
  }
18
- @app.should.respond_to :call
14
+ assert @app.respond_to?(:call)
19
15
 
20
16
  request = Rack::MockRequest.new(@app)
21
17
  response = request.get('/')
22
- response.should.be.ok
23
- response.body.should.equal 'Hello World'
18
+ assert response.ok?
19
+ assert_equal 'Hello World', response.body
24
20
  end
25
21
 
26
22
  it 'can be used as Rack middleware' do
@@ -35,15 +31,38 @@ describe 'Sinatra::Base' do
35
31
  end
36
32
  }
37
33
  middleware = mock_middleware.new(app)
38
- middleware.app.should.be app
34
+ assert_same app, middleware.app
39
35
 
40
36
  request = Rack::MockRequest.new(middleware)
41
37
  response = request.get('/')
42
- response.should.be.ok
43
- response.body.should.equal 'Hello World'
38
+ assert response.ok?
39
+ assert_equal 'Hello World', response.body
44
40
 
45
41
  response = request.get('/goodbye')
46
- response.should.be.ok
47
- response.body.should.equal 'Goodbye World'
42
+ assert response.ok?
43
+ assert_equal 'Goodbye World', response.body
44
+ end
45
+
46
+ it 'can take multiple definitions of a route' do
47
+ app = mock_app {
48
+ user_agent(/Foo/)
49
+ get '/foo' do
50
+ 'foo'
51
+ end
52
+
53
+ get '/foo' do
54
+ 'not foo'
55
+ end
56
+ }
57
+
58
+ request = Rack::MockRequest.new(app)
59
+ response = request.get('/foo', 'HTTP_USER_AGENT' => 'Foo')
60
+ assert response.ok?
61
+ assert_equal 'foo', response.body
62
+
63
+ request = Rack::MockRequest.new(app)
64
+ response = request.get('/foo')
65
+ assert response.ok?
66
+ assert_equal 'not foo', response.body
48
67
  end
49
68
  end
data/test/builder_test.rb CHANGED
@@ -1,10 +1,6 @@
1
- require 'test/spec'
2
- require 'sinatra/base'
3
- require 'sinatra/test'
1
+ require File.dirname(__FILE__) + '/helper'
4
2
 
5
3
  describe "Builder Templates" do
6
- include Sinatra::Test
7
-
8
4
  def builder_app(&block)
9
5
  mock_app {
10
6
  set :views, File.dirname(__FILE__) + '/views'
@@ -15,8 +11,8 @@ describe "Builder Templates" do
15
11
 
16
12
  it 'renders inline Builder strings' do
17
13
  builder_app { builder 'xml.instruct!' }
18
- should.be.ok
19
- body.should.equal %{<?xml version="1.0" encoding="UTF-8"?>\n}
14
+ assert ok?
15
+ assert_equal %{<?xml version="1.0" encoding="UTF-8"?>\n}, body
20
16
  end
21
17
 
22
18
  it 'renders inline blocks' do
@@ -26,8 +22,8 @@ describe "Builder Templates" do
26
22
  xml.couple @name
27
23
  end
28
24
  }
29
- should.be.ok
30
- body.should.equal "<couple>Frank &amp; Mary</couple>\n"
25
+ assert ok?
26
+ assert_equal "<couple>Frank &amp; Mary</couple>\n", body
31
27
  end
32
28
 
33
29
  it 'renders .builder files in views path' do
@@ -35,8 +31,8 @@ describe "Builder Templates" do
35
31
  @name = "Blue"
36
32
  builder :hello
37
33
  }
38
- should.be.ok
39
- body.should.equal %(<exclaim>You're my boy, Blue!</exclaim>\n)
34
+ assert ok?
35
+ assert_equal %(<exclaim>You're my boy, Blue!</exclaim>\n), body
40
36
  end
41
37
 
42
38
  it "renders with inline layouts" do
@@ -47,22 +43,22 @@ describe "Builder Templates" do
47
43
  get('/') { builder %(xml.em 'Hello World') }
48
44
  }
49
45
  get '/'
50
- should.be.ok
51
- body.should.equal "<layout>\n<em>Hello World</em>\n</layout>\n"
46
+ assert ok?
47
+ assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
52
48
  end
53
49
 
54
50
  it "renders with file layouts" do
55
51
  builder_app {
56
52
  builder %(xml.em 'Hello World'), :layout => :layout2
57
53
  }
58
- should.be.ok
59
- body.should.equal "<layout>\n<em>Hello World</em>\n</layout>\n"
54
+ assert ok?
55
+ assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
60
56
  end
61
57
 
62
58
  it "raises error if template not found" do
63
59
  mock_app {
64
60
  get('/') { builder :no_such_template }
65
61
  }
66
- lambda { get('/') }.should.raise(Errno::ENOENT)
62
+ assert_raise(Errno::ENOENT) { get('/') }
67
63
  end
68
64
  end
data/test/erb_test.rb CHANGED
@@ -1,10 +1,6 @@
1
- require 'test/spec'
2
- require 'sinatra/base'
3
- require 'sinatra/test'
1
+ require File.dirname(__FILE__) + '/helper'
4
2
 
5
3
  describe "ERB Templates" do
6
- include Sinatra::Test
7
-
8
4
  def erb_app(&block)
9
5
  mock_app {
10
6
  set :views, File.dirname(__FILE__) + '/views'
@@ -15,14 +11,14 @@ describe "ERB Templates" do
15
11
 
16
12
  it 'renders inline ERB strings' do
17
13
  erb_app { erb '<%= 1 + 1 %>' }
18
- should.be.ok
19
- body.should.equal '2'
14
+ assert ok?
15
+ assert_equal '2', body
20
16
  end
21
17
 
22
18
  it 'renders .erb files in views path' do
23
19
  erb_app { erb :hello }
24
- should.be.ok
25
- body.should.equal "Hello World\n"
20
+ assert ok?
21
+ assert_equal "Hello World\n", body
26
22
  end
27
23
 
28
24
  it 'takes a :locals option' do
@@ -30,8 +26,8 @@ describe "ERB Templates" do
30
26
  locals = {:foo => 'Bar'}
31
27
  erb '<%= foo %>', :locals => locals
32
28
  }
33
- should.be.ok
34
- body.should.equal 'Bar'
29
+ assert ok?
30
+ assert_equal 'Bar', body
35
31
  end
36
32
 
37
33
  it "renders with inline layouts" do
@@ -40,16 +36,15 @@ describe "ERB Templates" do
40
36
  get('/') { erb 'Sparta' }
41
37
  }
42
38
  get '/'
43
- should.be.ok
44
- body.should.equal 'THIS. IS. SPARTA!'
39
+ assert ok?
40
+ assert_equal 'THIS. IS. SPARTA!', body
45
41
  end
46
42
 
47
43
  it "renders with file layouts" do
48
44
  erb_app {
49
45
  erb 'Hello World', :layout => :layout2
50
46
  }
51
- should.be.ok
52
- body.should.equal "ERB Layout!\nHello World\n"
47
+ assert ok?
48
+ assert_equal "ERB Layout!\nHello World\n", body
53
49
  end
54
-
55
50
  end
data/test/filter_test.rb CHANGED
@@ -1,28 +1,24 @@
1
- require 'test/spec'
2
- require 'sinatra/base'
3
- require 'sinatra/test'
1
+ require File.dirname(__FILE__) + '/helper'
4
2
 
5
3
  describe "Filters" do
6
- include Sinatra::Test
7
-
8
4
  it "executes filters in the order defined" do
9
5
  count = 0
10
6
  mock_app do
11
7
  get('/') { 'Hello World' }
12
8
  before {
13
- count.should.be 0
9
+ assert_equal 0, count
14
10
  count = 1
15
11
  }
16
12
  before {
17
- count.should.be 1
13
+ assert_equal 1, count
18
14
  count = 2
19
15
  }
20
16
  end
21
17
 
22
18
  get '/'
23
- should.be.ok
24
- count.should.be 2
25
- body.should.equal 'Hello World'
19
+ assert ok?
20
+ assert_equal 2, count
21
+ assert_equal 'Hello World', body
26
22
  end
27
23
 
28
24
  it "allows filters to modify the request" do
@@ -33,7 +29,47 @@ describe "Filters" do
33
29
  }
34
30
 
35
31
  get '/foo'
36
- should.be.ok
37
- body.should.be == 'bar'
32
+ assert ok?
33
+ assert_equal 'bar', body
34
+ end
35
+
36
+ it "can modify instance variables available to routes" do
37
+ mock_app {
38
+ before { @foo = 'bar' }
39
+ get('/foo') { @foo }
40
+ }
41
+
42
+ get '/foo'
43
+ assert ok?
44
+ assert_equal 'bar', body
45
+ end
46
+
47
+ it "allows redirects in filters" do
48
+ mock_app {
49
+ before { redirect '/bar' }
50
+ get('/foo') do
51
+ fail 'before block should have halted processing'
52
+ 'ORLY?!'
53
+ end
54
+ }
55
+
56
+ get '/foo'
57
+ assert redirect?
58
+ assert_equal '/bar', response['Location']
59
+ assert_equal '', body
60
+ end
61
+
62
+ it "does not modify the response with its return value" do
63
+ mock_app {
64
+ before { 'Hello World!' }
65
+ get '/foo' do
66
+ assert_equal [], response.body
67
+ 'cool'
68
+ end
69
+ }
70
+
71
+ get '/foo'
72
+ assert ok?
73
+ assert_equal 'cool', body
38
74
  end
39
75
  end
data/test/haml_test.rb CHANGED
@@ -1,10 +1,6 @@
1
- require 'test/spec'
2
- require 'sinatra/base'
3
- require 'sinatra/test'
1
+ require File.dirname(__FILE__) + '/helper'
4
2
 
5
3
  describe "HAML Templates" do
6
- include Sinatra::Test
7
-
8
4
  def haml_app(&block)
9
5
  mock_app {
10
6
  set :views, File.dirname(__FILE__) + '/views'
@@ -15,14 +11,14 @@ describe "HAML Templates" do
15
11
 
16
12
  it 'renders inline HAML strings' do
17
13
  haml_app { haml '%h1 Hiya' }
18
- should.be.ok
19
- body.should.equal "<h1>Hiya</h1>\n"
14
+ assert ok?
15
+ assert_equal "<h1>Hiya</h1>\n", body
20
16
  end
21
17
 
22
18
  it 'renders .haml files in views path' do
23
19
  haml_app { haml :hello }
24
- should.be.ok
25
- body.should.equal "<h1>Hello From Haml</h1>\n"
20
+ assert ok?
21
+ assert_equal "<h1>Hello From Haml</h1>\n", body
26
22
  end
27
23
 
28
24
  it "renders with inline layouts" do
@@ -31,31 +27,31 @@ describe "HAML Templates" do
31
27
  get('/') { haml '%em Sparta' }
32
28
  }
33
29
  get '/'
34
- should.be.ok
35
- body.should.equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>\n"
30
+ assert ok?
31
+ assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>\n", body
36
32
  end
37
33
 
38
34
  it "renders with file layouts" do
39
35
  haml_app {
40
36
  haml 'Hello World', :layout => :layout2
41
37
  }
42
- should.be.ok
43
- body.should.equal "<h1>HAML Layout!</h1>\n<p>Hello World</p>\n"
38
+ assert ok?
39
+ assert_equal "<h1>HAML Layout!</h1>\n<p>Hello World</p>\n", body
44
40
  end
45
41
 
46
42
  it "raises error if template not found" do
47
43
  mock_app {
48
44
  get('/') { haml :no_such_template }
49
45
  }
50
- lambda { get('/') }.should.raise(Errno::ENOENT)
46
+ assert_raise(Errno::ENOENT) { get('/') }
51
47
  end
52
48
 
53
49
  it "passes HAML options to the Haml engine" do
54
50
  haml_app {
55
51
  haml "!!!\n%h1 Hello World", :options => {:format => :html5}
56
52
  }
57
- should.be.ok
58
- body.should.equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n"
53
+ assert ok?
54
+ assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
59
55
  end
60
56
 
61
57
  it "passes default HAML options to the Haml engine" do
@@ -66,7 +62,7 @@ describe "HAML Templates" do
66
62
  end
67
63
  }
68
64
  get '/'
69
- should.be.ok
70
- body.should.equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n"
65
+ assert ok?
66
+ assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
71
67
  end
72
68
  end