Permalink
Browse files

use Test::Unit style assertions in Sinatra specs

  • Loading branch information...
rtomayko committed Jan 14, 2009
1 parent 3d5e099 commit 72a6e01daf970e1263e61652887e47bbfe797027
View
@@ -2,7 +2,7 @@
describe 'Sinatra::Base' do
it 'includes Rack::Utils' do
- Sinatra::Base.should.include Rack::Utils
+ assert Sinatra::Base.included_modules.include?(Rack::Utils)
end
it 'can be used as a Rack application' do
@@ -11,12 +11,12 @@
'Hello World'
end
}
- @app.should.respond_to :call
+ assert @app.respond_to?(:call)
request = Rack::MockRequest.new(@app)
response = request.get('/')
- response.should.be.ok
- response.body.should.equal 'Hello World'
+ assert response.ok?
+ assert_equal 'Hello World', response.body
end
it 'can be used as Rack middleware' do
@@ -31,16 +31,16 @@
end
}
middleware = mock_middleware.new(app)
- middleware.app.should.be app
+ assert_same app, middleware.app
request = Rack::MockRequest.new(middleware)
response = request.get('/')
- response.should.be.ok
- response.body.should.equal 'Hello World'
+ assert response.ok?
+ assert_equal 'Hello World', response.body
response = request.get('/goodbye')
- response.should.be.ok
- response.body.should.equal 'Goodbye World'
+ assert response.ok?
+ assert_equal 'Goodbye World', response.body
end
it 'can take multiple definitions of a route' do
@@ -57,12 +57,12 @@
request = Rack::MockRequest.new(app)
response = request.get('/foo', 'HTTP_USER_AGENT' => 'Foo')
- response.should.be.ok
- response.body.should.equal 'foo'
+ assert response.ok?
+ assert_equal 'foo', response.body
request = Rack::MockRequest.new(app)
response = request.get('/foo')
- response.should.be.ok
- response.body.should.equal 'not foo'
+ assert response.ok?
+ assert_equal 'not foo', response.body
end
end
View
@@ -11,8 +11,8 @@ def builder_app(&block)
it 'renders inline Builder strings' do
builder_app { builder 'xml.instruct!' }
- should.be.ok
- body.should.equal %{<?xml version="1.0" encoding="UTF-8"?>\n}
+ assert ok?
+ assert_equal %{<?xml version="1.0" encoding="UTF-8"?>\n}, body
end
it 'renders inline blocks' do
@@ -22,17 +22,17 @@ def builder_app(&block)
xml.couple @name
end
}
- should.be.ok
- body.should.equal "<couple>Frank &amp; Mary</couple>\n"
+ assert ok?
+ assert_equal "<couple>Frank &amp; Mary</couple>\n", body
end
it 'renders .builder files in views path' do
builder_app {
@name = "Blue"
builder :hello
}
- should.be.ok
- body.should.equal %(<exclaim>You're my boy, Blue!</exclaim>\n)
+ assert ok?
+ assert_equal %(<exclaim>You're my boy, Blue!</exclaim>\n), body
end
it "renders with inline layouts" do
@@ -43,22 +43,22 @@ def builder_app(&block)
get('/') { builder %(xml.em 'Hello World') }
}
get '/'
- should.be.ok
- body.should.equal "<layout>\n<em>Hello World</em>\n</layout>\n"
+ assert ok?
+ assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
end
it "renders with file layouts" do
builder_app {
builder %(xml.em 'Hello World'), :layout => :layout2
}
- should.be.ok
- body.should.equal "<layout>\n<em>Hello World</em>\n</layout>\n"
+ assert ok?
+ assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
end
it "raises error if template not found" do
mock_app {
get('/') { builder :no_such_template }
}
- lambda { get('/') }.should.raise(Errno::ENOENT)
+ assert_raise(Errno::ENOENT) { get('/') }
end
end
View
@@ -11,23 +11,23 @@ def erb_app(&block)
it 'renders inline ERB strings' do
erb_app { erb '<%= 1 + 1 %>' }
- should.be.ok
- body.should.equal '2'
+ assert ok?
+ assert_equal '2', body
end
it 'renders .erb files in views path' do
erb_app { erb :hello }
- should.be.ok
- body.should.equal "Hello World\n"
+ assert ok?
+ assert_equal "Hello World\n", body
end
it 'takes a :locals option' do
erb_app {
locals = {:foo => 'Bar'}
erb '<%= foo %>', :locals => locals
}
- should.be.ok
- body.should.equal 'Bar'
+ assert ok?
+ assert_equal 'Bar', body
end
it "renders with inline layouts" do
@@ -36,16 +36,15 @@ def erb_app(&block)
get('/') { erb 'Sparta' }
}
get '/'
- should.be.ok
- body.should.equal 'THIS. IS. SPARTA!'
+ assert ok?
+ assert_equal 'THIS. IS. SPARTA!', body
end
it "renders with file layouts" do
erb_app {
erb 'Hello World', :layout => :layout2
}
- should.be.ok
- body.should.equal "ERB Layout!\nHello World\n"
+ assert ok?
+ assert_equal "ERB Layout!\nHello World\n", body
end
-
end
View
@@ -6,19 +6,19 @@
mock_app do
get('/') { 'Hello World' }
before {
- count.should.be 0
+ fail 'count != 0' if count != 0
count = 1
}
before {
- count.should.be 1
+ fail 'count != 1' if count != 1
count = 2
}
end
get '/'
- should.be.ok
- count.should.be 2
- body.should.equal 'Hello World'
+ assert ok?
+ assert_equal 2, count
+ assert_equal 'Hello World', body
end
it "allows filters to modify the request" do
@@ -29,7 +29,7 @@
}
get '/foo'
- should.be.ok
- body.should.be == 'bar'
+ assert ok?
+ assert_equal 'bar', body
end
end
View
@@ -11,14 +11,14 @@ def haml_app(&block)
it 'renders inline HAML strings' do
haml_app { haml '%h1 Hiya' }
- should.be.ok
- body.should.equal "<h1>Hiya</h1>\n"
+ assert ok?
+ assert_equal "<h1>Hiya</h1>\n", body
end
it 'renders .haml files in views path' do
haml_app { haml :hello }
- should.be.ok
- body.should.equal "<h1>Hello From Haml</h1>\n"
+ assert ok?
+ assert_equal "<h1>Hello From Haml</h1>\n", body
end
it "renders with inline layouts" do
@@ -27,31 +27,31 @@ def haml_app(&block)
get('/') { haml '%em Sparta' }
}
get '/'
- should.be.ok
- body.should.equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>\n"
+ assert ok?
+ assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>\n", body
end
it "renders with file layouts" do
haml_app {
haml 'Hello World', :layout => :layout2
}
- should.be.ok
- body.should.equal "<h1>HAML Layout!</h1>\n<p>Hello World</p>\n"
+ assert ok?
+ assert_equal "<h1>HAML Layout!</h1>\n<p>Hello World</p>\n", body
end
it "raises error if template not found" do
mock_app {
get('/') { haml :no_such_template }
}
- lambda { get('/') }.should.raise(Errno::ENOENT)
+ assert_raise(Errno::ENOENT) { get('/') }
end
it "passes HAML options to the Haml engine" do
haml_app {
haml "!!!\n%h1 Hello World", :options => {:format => :html5}
}
- should.be.ok
- body.should.equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n"
+ assert ok?
+ assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
end
it "passes default HAML options to the Haml engine" do
@@ -62,7 +62,7 @@ def haml_app(&block)
end
}
get '/'
- should.be.ok
- body.should.equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n"
+ assert ok?
+ assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
end
end
View
@@ -1,12 +1,16 @@
-require 'test/spec'
+begin
+ require 'test/spec'
+rescue LoadError
+ require 'rubygems'
+ require 'test/spec'
+end
$:.unshift File.dirname(File.dirname(__FILE__)) + '/lib'
require 'sinatra/base'
require 'sinatra/test'
require 'sinatra/test/spec'
module Sinatra::Test
-
# Sets up a Sinatra::Base subclass defined with the block
# given. Used in setup or individual spec methods to establish
# the application.
Oops, something went wrong.

0 comments on commit 72a6e01

Please sign in to comment.