Permalink
Browse files

Port specs to bacon format.

  • Loading branch information...
1 parent fe97e9b commit 79e6e283e3d1af32f0dfb1053fa7d9536fe6d05f @mipearson committed Jan 1, 2013
@@ -2,29 +2,29 @@
require 'rack/contrib/accept_format'
require 'rack/mime'
-context "Rack::AcceptFormat" do
+describe "Rack::AcceptFormat" do
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, env['PATH_INFO']] }
- specify "should do nothing when a format extension is already provided" do
+ it "should do nothing when a format extension is already provided" do
request = Rack::MockRequest.env_for("/resource.json")
body = Rack::AcceptFormat.new(app).call(request).last
body.should == "/resource.json"
end
- context "default extention" do
- specify "should allow custom default" do
+ describe "default extention" do
+ it "should allow custom default" do
request = Rack::MockRequest.env_for("/resource")
body = Rack::AcceptFormat.new(app, '.xml').call(request).last
body.should == "/resource.xml"
end
- specify "should default to html" do
+ it "should default to html" do
request = Rack::MockRequest.env_for("/resource")
body = Rack::AcceptFormat.new(app).call(request).last
body.should == "/resource.html"
end
- specify "should notmalize custom extention" do
+ it "should notmalize custom extention" do
request = Rack::MockRequest.env_for("/resource")
body = Rack::AcceptFormat.new(app,'xml').call(request).last #no dot prefix
@@ -35,35 +35,35 @@
end
end
- context "there is no format extension" do
+ describe "there is no format extension" do
Rack::Mime::MIME_TYPES.clear
def mime(ext, type)
ext = ".#{ext}" unless ext.to_s[0] == ?.
Rack::Mime::MIME_TYPES[ext.to_s] = type
end
- specify "should add the default extension if no Accept header" do
+ it "should add the default extension if no Accept header" do
request = Rack::MockRequest.env_for("/resource")
body = Rack::AcceptFormat.new(app).call(request).last
body.should == "/resource.html"
end
- specify "should add the default extension if the Accept header is not registered in the Mime::Types" do
+ it "should add the default extension if the Accept header is not registered in the Mime::Types" do
request = Rack::MockRequest.env_for("/resource", 'HTTP_ACCEPT' => 'application/json;q=1.0, text/html;q=0.8, */*;q=0.1')
body = Rack::AcceptFormat.new(app).call(request).last
body.should == "/resource.html"
end
- specify "should add the correct extension if the Accept header is registered in the Mime::Types" do
+ it "should add the correct extension if the Accept header is registered in the Mime::Types" do
mime :json, 'application/json'
request = Rack::MockRequest.env_for("/resource", 'HTTP_ACCEPT' => 'application/json;q=1.0, text/html;q=0.8, */*;q=0.1')
body = Rack::AcceptFormat.new(app).call(request).last
body.should == "/resource.json"
end
end
- specify "shouldn't confuse extention when there are dots in path" do
+ it "shouldn't confuse extention when there are dots in path" do
request = Rack::MockRequest.env_for("/parent.resource/resource")
body = Rack::AcceptFormat.new(app, '.html').call(request).last
body.should == "/parent.resource/resource.html"
View
@@ -1,9 +1,9 @@
require 'rack/mock'
require 'rack/contrib/access'
-context "Rack::Access" do
+describe "Rack::Access" do
- setup do
+ before do
@app = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ['hello']] }
@mock_addr_1 = '111.111.111.111'
@mock_addr_2 = '192.168.1.222'
@@ -19,49 +19,49 @@ def middleware(options = {})
Rack::Access.new(@app, options)
end
- specify "default configuration should deny non-local requests" do
+ it "default configuration should deny non-local requests" do
app = middleware
status, headers, body = app.call(mock_env(@mock_addr_1))
status.should.equal 403
body.should.equal []
end
- specify "default configuration should allow requests from 127.0.0.1" do
+ it "default configuration should allow requests from 127.0.0.1" do
app = middleware
status, headers, body = app.call(mock_env(@mock_addr_localhost))
status.should.equal 200
body.should.equal ['hello']
end
- specify "should allow remote addresses in allow_ipmasking" do
+ it "should allow remote addresses in allow_ipmasking" do
app = middleware('/' => [@mock_addr_1])
status, headers, body = app.call(mock_env(@mock_addr_1))
status.should.equal 200
body.should.equal ['hello']
end
- specify "should deny remote addresses not in allow_ipmasks" do
+ it "should deny remote addresses not in allow_ipmasks" do
app = middleware('/' => [@mock_addr_1])
status, headers, body = app.call(mock_env(@mock_addr_2))
status.should.equal 403
body.should.equal []
end
- specify "should allow remote addresses in allow_ipmasks range" do
+ it "should allow remote addresses in allow_ipmasks range" do
app = middleware('/' => [@mock_addr_range])
status, headers, body = app.call(mock_env(@mock_addr_2))
status.should.equal 200
body.should.equal ['hello']
end
- specify "should deny remote addresses not in allow_ipmasks range" do
+ it "should deny remote addresses not in allow_ipmasks range" do
app = middleware('/' => [@mock_addr_range])
status, headers, body = app.call(mock_env(@mock_addr_1))
status.should.equal 403
body.should.equal []
end
- specify "should allow remote addresses in one of allow_ipmasking" do
+ it "should allow remote addresses in one of allow_ipmasking" do
app = middleware('/' => [@mock_addr_range, @mock_addr_localhost])
status, headers, body = app.call(mock_env(@mock_addr_2))
@@ -73,14 +73,14 @@ def middleware(options = {})
body.should.equal ['hello']
end
- specify "should deny remote addresses not in one of allow_ipmasks" do
+ it "should deny remote addresses not in one of allow_ipmasks" do
app = middleware('/' => [@mock_addr_range, @mock_addr_localhost])
status, headers, body = app.call(mock_env(@mock_addr_1))
status.should.equal 403
body.should.equal []
end
- specify "handles paths correctly" do
+ it "handles paths correctly" do
app = middleware({
'http://foo.org/bar' => [@mock_addr_localhost],
'/foo' => [@mock_addr_localhost],
@@ -2,8 +2,8 @@
require 'rack/mock'
require 'rack/contrib/backstage'
-context "Rack::Backstage" do
- specify "shows maintenances page if present" do
+describe "Rack::Backstage" do
+ it "shows maintenances page if present" do
app = Rack::Builder.new do
use Rack::Backstage, 'test/Maintenance.html'
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
@@ -13,7 +13,7 @@
response.status.should.equal(503)
end
- specify "passes on request if page is not present" do
+ it "passes on request if page is not present" do
app = Rack::Builder.new do
use Rack::Backstage, 'test/Nonsense.html'
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
@@ -1,4 +1,5 @@
require 'rack/mock'
+require 'rack/contrib/callbacks'
class Flame
def call(env)
@@ -36,8 +37,8 @@ def call(response)
end
end
-context "Rack::Callbacks" do
- specify "works for love and small stack trace" do
+describe "Rack::Callbacks" do
+ it "works for love and small stack trace" do
callback_app = Rack::Callbacks.new do
before Flame
before Pacify, "with love"
@@ -2,9 +2,9 @@
require 'rack/builder'
require 'rack/contrib/common_cookies'
-context Rack::CommonCookies do
+describe Rack::CommonCookies do
- setup do
+ before do
@app = Rack::Builder.new do
use Rack::CommonCookies
run lambda {|env| [200, {'Set-Cookie' => env['HTTP_COOKIE']}, []] }
@@ -19,87 +19,87 @@ def make_request(domain, cookies='key=value')
request.get '/', 'HTTP_COOKIE' => cookies, 'HTTP_HOST' => domain
end
- specify 'should use .domain.com for cookies from domain.com' do
+ it 'should use .domain.com for cookies from domain.com' do
response = make_request 'domain.com'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.com'
end
- specify 'should use .domain.com for cookies from www.domain.com' do
+ it 'should use .domain.com for cookies from www.domain.com' do
response = make_request 'www.domain.com'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.com'
end
- specify 'should use .domain.com for cookies from subdomain.domain.com' do
+ it 'should use .domain.com for cookies from subdomain.domain.com' do
response = make_request 'subdomain.domain.com'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.com'
end
- specify 'should use .domain.com for cookies from 0.subdomain1.subdomain2.domain.com' do
+ it 'should use .domain.com for cookies from 0.subdomain1.subdomain2.domain.com' do
response = make_request '0.subdomain1.subdomain2.domain.com'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.com'
end
- specify 'should use .domain.local for cookies from domain.local' do
+ it 'should use .domain.local for cookies from domain.local' do
response = make_request '0.subdomain1.subdomain2.domain.com'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.com'
end
- specify 'should use .domain.local for cookies from subdomain.domain.local' do
+ it 'should use .domain.local for cookies from subdomain.domain.local' do
response = make_request 'subdomain.domain.local'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.local'
end
- specify 'should use .domain.com.ua for cookies from domain.com.ua' do
+ it 'should use .domain.com.ua for cookies from domain.com.ua' do
response = make_request 'domain.com.ua'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.com.ua'
end
- specify 'should use .domain.com.ua for cookies from subdomain.domain.com.ua' do
+ it 'should use .domain.com.ua for cookies from subdomain.domain.com.ua' do
response = make_request 'subdomain.domain.com.ua'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.com.ua'
end
- specify 'should use .domain.co.uk for cookies from domain.co.uk' do
+ it 'should use .domain.co.uk for cookies from domain.co.uk' do
response = make_request 'domain.co.uk'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.co.uk'
end
- specify 'should use .domain.co.uk for cookies from subdomain.domain.co.uk' do
+ it 'should use .domain.co.uk for cookies from subdomain.domain.co.uk' do
response = make_request 'subdomain.domain.co.uk'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.co.uk'
end
- specify 'should use .domain.eu.com for cookies from domain.eu.com' do
+ it 'should use .domain.eu.com for cookies from domain.eu.com' do
response = make_request 'domain.eu.com'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.eu.com'
end
- specify 'should use .domain.eu.com for cookies from subdomain.domain.eu.com' do
+ it 'should use .domain.eu.com for cookies from subdomain.domain.eu.com' do
response = make_request 'subdomain.domain.eu.com'
response.headers['Set-Cookie'].should == 'key=value; domain=.domain.eu.com'
end
- specify 'should work with multiple cookies' do
+ it 'should work with multiple cookies' do
response = make_request 'sub.domain.bz', "key=value\nkey1=value2"
response.headers['Set-Cookie'].should == "key=value; domain=.domain.bz\nkey1=value2; domain=.domain.bz"
end
- specify 'should work with cookies which have explicit domain' do
+ it 'should work with cookies which have explicit domain' do
response = make_request 'sub.domain.bz', "key=value; domain=domain.bz"
response.headers['Set-Cookie'].should == "key=value; domain=.domain.bz"
end
- specify 'should not touch cookies if domain is localhost' do
+ it 'should not touch cookies if domain is localhost' do
response = make_request 'localhost'
response.headers['Set-Cookie'].should == "key=value"
end
- specify 'should not touch cookies if domain is ip address' do
+ it 'should not touch cookies if domain is ip address' do
response = make_request '127.0.0.1'
response.headers['Set-Cookie'].should == "key=value"
end
- specify 'should use .domain.com for cookies from subdomain.domain.com:3000' do
+ it 'should use .domain.com for cookies from subdomain.domain.com:3000' do
response = make_request 'subdomain.domain.com:3000'
response.headers['Set-Cookie'].should == "key=value; domain=.domain.com"
end
View
@@ -1,9 +1,9 @@
require 'rack/mock'
require 'rack/contrib/config'
-context "Rack::Config" do
+describe "Rack::Config" do
- specify "should accept a block that modifies the environment" do
+ it "should accept a block that modifies the environment" do
app = Rack::Builder.new do
use Rack::Lint
use Rack::ContentLength
@@ -1,7 +1,7 @@
require 'rack/contrib'
-context "Rack::Contrib" do
- specify "should expose release" do
+describe "Rack::Contrib" do
+ it "should expose release" do
Rack::Contrib.should.respond_to :release
end
end
View
@@ -1,8 +1,8 @@
require 'rack/mock'
require 'rack/contrib/cookies'
-context "Rack::Cookies" do
- specify "should be able to read received cookies" do
+describe "Rack::Cookies" do
+ it "should be able to read received cookies" do
app = lambda { |env|
cookies = env['rack.cookies']
foo, quux = cookies[:foo], cookies['quux']
@@ -14,7 +14,7 @@
response.body.should.equal('foo: bar, quux: h&m')
end
- specify "should be able to set new cookies" do
+ it "should be able to set new cookies" do
app = lambda { |env|
cookies = env['rack.cookies']
cookies[:foo] = 'bar'
@@ -27,7 +27,7 @@
response.headers['Set-Cookie'].should.equal("quux=h%26m; path=/\nfoo=bar; path=/")
end
- specify "should be able to set cookie with options" do
+ it "should be able to set cookie with options" do
app = lambda { |env|
cookies = env['rack.cookies']
cookies['foo'] = { :value => 'bar', :path => '/login', :secure => true }
@@ -39,7 +39,7 @@
response.headers['Set-Cookie'].should.equal('foo=bar; path=/login; secure')
end
- specify "should be able to delete received cookies" do
+ it "should be able to delete received cookies" do
app = lambda { |env|
cookies = env['rack.cookies']
cookies.delete(:foo)
Oops, something went wrong.

0 comments on commit 79e6e28

Please sign in to comment.