Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Port specs to bacon format.

  • Loading branch information...
commit 79e6e283e3d1af32f0dfb1053fa7d9536fe6d05f 1 parent fe97e9b
@mipearson authored
Showing with 255 additions and 255 deletions.
  1. +11 −11 test/spec_rack_accept_format.rb
  2. +11 −11 test/spec_rack_access.rb
  3. +3 −3 test/spec_rack_backstage.rb
  4. +3 −2 test/spec_rack_callbacks.rb
  5. +19 −19 test/spec_rack_common_cookies.rb
  6. +2 −2 test/spec_rack_config.rb
  7. +2 −2 test/spec_rack_contrib.rb
  8. +5 −5 test/spec_rack_cookies.rb
  9. +8 −8 test/spec_rack_csshttprequest.rb
  10. +7 −7 test/spec_rack_deflect.rb
  11. +2 −2 test/spec_rack_evil.rb
  12. +8 −8 test/spec_rack_expectation_cascade.rb
  13. +2 −2 test/spec_rack_garbagecollector.rb
  14. +8 −8 test/spec_rack_host_meta.rb
  15. +25 −25 test/spec_rack_jsonp.rb
  16. +2 −2 test/spec_rack_lighttpd_script_name_fix.rb
  17. +9 −9 test/spec_rack_locale.rb
  18. +17 −17 test/spec_rack_mailexceptions.rb
  19. +5 −5 test/spec_rack_nested_params.rb
  20. +2 −2 test/spec_rack_not_found.rb
  21. +12 −13 test/spec_rack_post_body_content_type_parser.rb
  22. +3 −3 test/spec_rack_proctitle.rb
  23. +6 −6 test/spec_rack_profiler.rb
  24. +7 −7 test/spec_rack_relative_redirect.rb
  25. +18 −18 test/spec_rack_response_cache.rb
  26. +5 −5 test/spec_rack_response_headers.rb
  27. +5 −5 test/spec_rack_runtime.rb
  28. +10 −10 test/spec_rack_sendfile.rb
  29. +19 −19 test/spec_rack_simple_endpoint.rb
  30. +15 −15 test/spec_rack_static_cache.rb
  31. +4 −4 test/spec_rack_try_static.rb
View
22 test/spec_rack_accept_format.rb
@@ -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,7 +35,7 @@
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)
@@ -43,19 +43,19 @@ def mime(ext, type)
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
@@ -63,7 +63,7 @@ def mime(ext, type)
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
22 test/spec_rack_access.rb
@@ -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],
View
6 test/spec_rack_backstage.rb
@@ -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!"]] }
View
5 test/spec_rack_callbacks.rb
@@ -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"
View
38 test/spec_rack_common_cookies.rb
@@ -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
4 test/spec_rack_config.rb
@@ -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
View
4 test/spec_rack_contrib.rb
@@ -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
10 test/spec_rack_cookies.rb
@@ -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)
View
16 test/spec_rack_csshttprequest.rb
@@ -4,7 +4,7 @@
require 'csshttprequest'
require 'rack/contrib/csshttprequest'
- context "Rack::CSSHTTPRequest" do
+ describe "Rack::CSSHTTPRequest" do
before(:each) do
@test_body = '{"bar":"foo"}'
@@ -13,44 +13,44 @@
@app = lambda { |env| [200, @test_headers, [@test_body]] }
end
- specify "env['csshttprequest.chr'] should be set to true when \
+ it "env['csshttprequest.chr'] should be set to true when \
PATH_INFO ends with '.chr'" do
request = Rack::MockRequest.env_for("/blah.chr", :lint => true, :fatal => true)
Rack::CSSHTTPRequest.new(@app).call(request)
request['csshttprequest.chr'].should.equal true
end
- specify "env['csshttprequest.chr'] should be set to true when \
+ it "env['csshttprequest.chr'] should be set to true when \
request parameter _format == 'chr'" do
request = Rack::MockRequest.env_for("/?_format=chr", :lint => true, :fatal => true)
Rack::CSSHTTPRequest.new(@app).call(request)
request['csshttprequest.chr'].should.equal true
end
- specify "should not change the headers or response when !env['csshttprequest.chr']" do
+ it "should not change the headers or response when !env['csshttprequest.chr']" do
request = Rack::MockRequest.env_for("/", :lint => true, :fatal => true)
status, headers, response = Rack::CSSHTTPRequest.new(@app).call(request)
headers.should.equal @test_headers
response.join.should.equal @test_body
end
- context "when env['csshttprequest.chr']" do
+ describe "when env['csshttprequest.chr']" do
before(:each) do
@request = Rack::MockRequest.env_for("/",
'csshttprequest.chr' => true, :lint => true, :fatal => true)
end
- specify "should modify the content length to the correct value" do
+ it "should modify the content length to the correct value" do
headers = Rack::CSSHTTPRequest.new(@app).call(@request)[1]
headers['Content-Length'].should.equal @encoded_body.length.to_s
end
- specify "should modify the content type to the correct value" do
+ it "should modify the content type to the correct value" do
headers = Rack::CSSHTTPRequest.new(@app).call(@request)[1]
headers['Content-Type'].should.equal 'text/css'
end
- specify "should not modify any other headers" do
+ it "should not modify any other headers" do
headers = Rack::CSSHTTPRequest.new(@app).call(@request)[1]
headers.should.equal @test_headers.merge({
'Content-Type' => 'text/css',
View
14 test/spec_rack_deflect.rb
@@ -1,9 +1,9 @@
require 'rack/mock'
require 'rack/contrib/deflect'
-context "Rack::Deflect" do
+describe "Rack::Deflect" do
- setup do
+ before do
@app = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ['cookies']] }
@mock_addr_1 = '111.111.111.111'
@mock_addr_2 = '222.222.222.222'
@@ -18,14 +18,14 @@ def mock_deflect options = {}
Rack::Deflect.new @app, options
end
- specify "should allow regular requests to follow through" do
+ it "should allow regular requests to follow through" do
app = mock_deflect
status, headers, body = app.call mock_env(@mock_addr_1)
status.should.equal 200
body.should.equal ['cookies']
end
- specify "should deflect requests exceeding the request threshold" do
+ it "should deflect requests exceeding the request threshold" do
log = StringIO.new
app = mock_deflect :request_threshold => 5, :interval => 10, :block_duration => 10, :log => log
env = mock_env @mock_addr_1
@@ -48,7 +48,7 @@ def mock_deflect options = {}
log.string.should.match(/^deflect\(\d+\/\d+\/\d+\): blocked 111.111.111.111\n/)
end
- specify "should expire blocking" do
+ it "should expire blocking" do
log = StringIO.new
app = mock_deflect :request_threshold => 5, :interval => 2, :block_duration => 2, :log => log
env = mock_env @mock_addr_1
@@ -79,7 +79,7 @@ def mock_deflect options = {}
log.string.should.match(/deflect.*: blocked 111\.111\.111\.111\ndeflect.*: released 111\.111\.111\.111\n/)
end
- specify "should allow whitelisting of remote addresses" do
+ it "should allow whitelisting of remote addresses" do
app = mock_deflect :whitelist => [@mock_addr_1], :request_threshold => 5, :interval => 2
env = mock_env @mock_addr_1
@@ -91,7 +91,7 @@ def mock_deflect options = {}
end
end
- specify "should allow blacklisting of remote addresses" do
+ it "should allow blacklisting of remote addresses" do
app = mock_deflect :blacklist => [@mock_addr_2]
status, headers, body = app.call mock_env(@mock_addr_1)
View
4 test/spec_rack_evil.rb
@@ -2,13 +2,13 @@
require 'rack/contrib/evil'
require 'erb'
-context "Rack::Evil" do
+describe "Rack::Evil" do
app = lambda do |env|
template = ERB.new("<%= throw :response, [404, {'Content-Type' => 'text/html'}, 'Never know where it comes from'] %>")
[200, {'Content-Type' => 'text/plain'}, template.result(binding)]
end
- specify "should enable the app to return the response from anywhere" do
+ it "should enable the app to return the response from anywhere" do
status, headers, body = Rack::Evil.new(app).call({})
status.should.equal 404
View
16 test/spec_rack_expectation_cascade.rb
@@ -1,8 +1,8 @@
require 'rack/mock'
require 'rack/contrib/expectation_cascade'
-context "Rack::ExpectationCascade" do
- specify "with no apps returns a 404 if no expectation header was set" do
+describe "Rack::ExpectationCascade" do
+ it "with no apps returns a 404 if no expectation header was set" do
app = Rack::ExpectationCascade.new
env = {}
response = app.call(env)
@@ -10,7 +10,7 @@
env.should.equal({})
end
- specify "with no apps returns a 417 if expectation header was set" do
+ it "with no apps returns a 417 if expectation header was set" do
app = Rack::ExpectationCascade.new
env = {"Expect" => "100-continue"}
response = app.call(env)
@@ -18,7 +18,7 @@
env.should.equal({"Expect" => "100-continue"})
end
- specify "returns first successful response" do
+ it "returns first successful response" do
app = Rack::ExpectationCascade.new do |cascade|
cascade << lambda { |env| [417, {"Content-Type" => "text/plain"}, []] }
cascade << lambda { |env| [200, {"Content-Type" => "text/plain"}, ["OK"]] }
@@ -28,7 +28,7 @@
response[2][0].should.equal "OK"
end
- specify "expectation is set if it has not been already" do
+ it "expectation is set if it has not been already" do
app = Rack::ExpectationCascade.new do |cascade|
cascade << lambda { |env| [200, {"Content-Type" => "text/plain"}, ["Expect: #{env["Expect"]}"]] }
end
@@ -37,7 +37,7 @@
response[2][0].should.equal "Expect: 100-continue"
end
- specify "returns a 404 if no apps where matched and no expectation header was set" do
+ it "returns a 404 if no apps where matched and no expectation header was set" do
app = Rack::ExpectationCascade.new do |cascade|
cascade << lambda { |env| [417, {"Content-Type" => "text/plain"}, []] }
end
@@ -46,7 +46,7 @@
response[2][0].should.equal nil
end
- specify "returns a 417 if no apps where matched and a expectation header was set" do
+ it "returns a 417 if no apps where matched and a expectation header was set" do
app = Rack::ExpectationCascade.new do |cascade|
cascade << lambda { |env| [417, {"Content-Type" => "text/plain"}, []] }
end
@@ -55,7 +55,7 @@
response[2][0].should.equal nil
end
- specify "nests expectation cascades" do
+ it "nests expectation cascades" do
app = Rack::ExpectationCascade.new do |c1|
c1 << Rack::ExpectationCascade.new do |c2|
c2 << lambda { |env| [417, {"Content-Type" => "text/plain"}, []] }
View
4 test/spec_rack_garbagecollector.rb
@@ -1,9 +1,9 @@
require 'rack/mock'
require 'rack/contrib/garbagecollector'
-context 'Rack::GarbageCollector' do
+describe 'Rack::GarbageCollector' do
- specify 'starts the garbage collector after each request' do
+ it 'starts the garbage collector after each request' do
app = lambda { |env|
[200, {'Content-Type'=>'text/plain'}, ['Hello World']] }
Rack::GarbageCollector.new(app).call({})
View
16 test/spec_rack_host_meta.rb
@@ -2,9 +2,9 @@
require 'rack/contrib/host_meta'
require 'rack/contrib/not_found'
-context "Rack::HostMeta" do
+describe "Rack::HostMeta" do
- setup do
+ before do
app = Rack::Builder.new do
use Rack::Lint
use Rack::ContentLength
@@ -18,30 +18,30 @@
@response = Rack::MockRequest.new(app).get('/host-meta')
end
- specify "should respond to /host-meta" do
+ it "should respond to /host-meta" do
@response.status.should.equal 200
end
- specify "should respond with the correct media type" do
+ it "should respond with the correct media type" do
@response['Content-Type'].should.equal 'application/host-meta'
end
- specify "should include a Link entry for each Link item in the config block" do
+ it "should include a Link entry for each Link item in the config block" do
@response.body.should.match(/Link:\s*<\/robots.txt>;.*\n/)
@response.body.should.match(/Link:\s*<\/w3c\/p3p.xml>;.*/)
end
- specify "should include a Link-Pattern entry for each Link-Pattern item in the config" do
+ it "should include a Link-Pattern entry for each Link-Pattern item in the config" do
@response.body.should.match(/Link-Pattern:\s*<\{uri\};json_schema>;.*/)
end
- specify "should include a rel attribute for each Link or Link-Pattern entry where specified" do
+ it "should include a rel attribute for each Link or Link-Pattern entry where specified" do
@response.body.should.match(/rel="robots"/)
@response.body.should.match(/rel="privacy"/)
@response.body.should.match(/rel="describedby"/)
end
- specify "should include a type attribute for each Link or Link-Pattern entry where specified" do
+ it "should include a type attribute for each Link or Link-Pattern entry where specified" do
@response.body.should.match(/Link:\s*<\/w3c\/p3p.xml>;.*type.*application\/p3p.xml/)
@response.body.should.match(/Link-Pattern:\s*<\{uri\};json_schema>;.*type.*application\/x-schema\+json/)
end
View
50 test/spec_rack_jsonp.rb
@@ -1,10 +1,10 @@
require 'rack/mock'
require 'rack/contrib/jsonp'
-context "Rack::JSONP" do
+describe "Rack::JSONP" do
- context "when a callback parameter is provided" do
- specify "should wrap the response body in the Javascript callback if JSON" do
+ describe "when a callback parameter is provided" do
+ it "should wrap the response body in the Javascript callback if JSON" do
test_body = '{"bar":"foo"}'
callback = 'foo'
app = lambda { |env| [200, {'Content-Type' => 'application/json'}, [test_body]] }
@@ -13,7 +13,7 @@
body.should.equal ["#{callback}(#{test_body})"]
end
- specify "should not wrap the response body in a callback if body is not JSON" do
+ it "should not wrap the response body in a callback if body is not JSON" do
test_body = '{"bar":"foo"}'
callback = 'foo'
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, [test_body]] }
@@ -22,7 +22,7 @@
body.should.equal ['{"bar":"foo"}']
end
- specify "should update content length if it was set" do
+ it "should update content length if it was set" do
test_body = '{"bar":"foo"}'
callback = 'foo'
app = lambda { |env| [200, {'Content-Type' => 'application/json', 'Content-Length' => test_body.length}, [test_body]] }
@@ -33,7 +33,7 @@
headers['Content-Length'].should.equal(expected_length.to_s)
end
- specify "should not touch content length if not set" do
+ it "should not touch content length if not set" do
test_body = '{"bar":"foo"}'
callback = 'foo'
app = lambda { |env| [200, {'Content-Type' => 'application/json'}, [test_body]] }
@@ -42,7 +42,7 @@
headers['Content-Length'].should.equal nil
end
- specify "should modify the content type to application/javascript" do
+ it "should modify the content type to application/javascript" do
test_body = '{"bar":"foo"}'
callback = 'foo'
app = lambda { |env| [200, {'Content-Type' => 'application/json'}, [test_body]] }
@@ -51,7 +51,7 @@
headers['Content-Type'].should.equal('application/javascript')
end
- specify "should not allow literal U+2028 or U+2029" do
+ it "should not allow literal U+2028 or U+2029" do
test_body = unless "\u2028" == 'u2028'
"{\"bar\":\"\u2028 and \u2029\"}"
else
@@ -68,8 +68,8 @@
end
end
- context "but is empty" do
- specify "should " do
+ describe "but is empty" do
+ it "should " do
test_body = '{"bar":"foo"}'
callback = ''
app = lambda { |env| [200, {'Content-Type' => 'application/json'}, [test_body]] }
@@ -79,9 +79,9 @@
end
end
- context 'but is invalid' do
- context 'with content-type application/json' do
- specify 'should return "Bad Request"' do
+ describe 'but is invalid' do
+ describe 'with content-type application/json' do
+ it 'should return "Bad Request"' do
test_body = '{"bar":"foo"}'
callback = '*'
content_type = 'application/json'
@@ -91,7 +91,7 @@
body.should.equal ['Bad Request']
end
- specify 'should return set the response code to 400' do
+ it 'should return set the response code to 400' do
test_body = '{"bar":"foo"}'
callback = '*'
content_type = 'application/json'
@@ -102,8 +102,8 @@
end
end
- context 'with content-type text/plain' do
- specify 'should return "Good Request"' do
+ describe 'with content-type text/plain' do
+ it 'should return "Good Request"' do
test_body = 'Good Request'
callback = '*'
content_type = 'text/plain'
@@ -113,7 +113,7 @@
body.should.equal ['Good Request']
end
- specify 'should not change the response code from 200' do
+ it 'should not change the response code from 200' do
test_body = '{"bar":"foo"}'
callback = '*'
content_type = 'text/plain'
@@ -125,7 +125,7 @@
end
end
- context "with XSS vulnerability attempts" do
+ describe "with XSS vulnerability attempts" do
def request(callback, body = '{"bar":"foo"}')
app = lambda { |env| [200, {'Content-Type' => 'application/json'}, [body]] }
request = Rack::MockRequest.env_for("/", :params => "foo=bar&callback=#{callback}")
@@ -139,19 +139,19 @@ def assert_bad_request(response)
body.should.equal ["Bad Request"]
end
- specify "should return bad request for callback with invalid characters" do
+ it "should return bad request for callback with invalid characters" do
assert_bad_request(request("foo<bar>baz()$"))
end
- specify "should return bad request for callbacks with <script> tags" do
+ it "should return bad request for callbacks with <script> tags" do
assert_bad_request(request("foo<script>alert(1)</script>"))
end
- specify "should return bad requests for callbacks with multiple statements" do
+ it "should return bad requests for callbacks with multiple statements" do
assert_bad_request(request("foo%3balert(1)//")) # would render: "foo;alert(1)//"
end
- specify "should not return a bad request for callbacks with dots in the callback" do
+ it "should not return a bad request for callbacks with dots in the callback" do
status, headers, body = request(callback = "foo.bar.baz", test_body = '{"foo":"bar"}')
status.should.equal 200
body.should.equal ["#{callback}(#{test_body})"]
@@ -160,7 +160,7 @@ def assert_bad_request(response)
end
- specify "should not change anything if no callback param is provided" do
+ it "should not change anything if no callback param is provided" do
test_body = ['{"bar":"foo"}']
app = lambda { |env| [200, {'Content-Type' => 'application/json'}, test_body] }
request = Rack::MockRequest.env_for("/", :params => "foo=bar")
@@ -168,7 +168,7 @@ def assert_bad_request(response)
body.should.equal test_body
end
- specify "should not change anything if it's not a json response" do
+ it "should not change anything if it's not a json response" do
test_body = '<html><body>404 Not Found</body></html>'
app = lambda { |env| [404, {'Content-Type' => 'text/html'}, [test_body]] }
request = Rack::MockRequest.env_for("/", :params => "callback=foo", 'HTTP_ACCEPT' => 'application/json')
@@ -176,7 +176,7 @@ def assert_bad_request(response)
body.should.equal [test_body]
end
- specify "should not change anything if there is no Content-Type header" do
+ it "should not change anything if there is no Content-Type header" do
test_body = '<html><body>404 Not Found</body></html>'
app = lambda { |env| [404, {}, [test_body]] }
request = Rack::MockRequest.env_for("/", :params => "callback=foo", 'HTTP_ACCEPT' => 'application/json')
View
4 test/spec_rack_lighttpd_script_name_fix.rb
@@ -1,8 +1,8 @@
require 'rack/mock'
require 'rack/contrib/lighttpd_script_name_fix'
-context "Rack::LighttpdScriptNameFix" do
- specify "corrects SCRIPT_NAME and PATH_INFO set by lighttpd " do
+describe "Rack::LighttpdScriptNameFix" do
+ it "corrects SCRIPT_NAME and PATH_INFO set by lighttpd " do
env = {
"PATH_INFO" => "/foo/bar/baz",
"SCRIPT_NAME" => "/hello"
View
18 test/spec_rack_locale.rb
@@ -1,8 +1,8 @@
require 'rack/mock'
-context "Rack::Locale" do
+describe "Rack::Locale" do
- setup do
+ before do
begin
require 'rack/contrib/locale'
rescue LoadError
@@ -21,33 +21,33 @@ def response_with_languages(accept_languages)
Rack::MockRequest.new(app).get('/', { 'HTTP_ACCEPT_LANGUAGE' => accept_languages } )
end
- specify 'should use I18n.default_locale if no languages are requested' do
+ it 'should use I18n.default_locale if no languages are requested' do
I18n.default_locale = :zh
response_with_languages(nil).body.should.equal('zh')
end
- specify 'should treat an empty qvalue as 1.0' do
+ it 'should treat an empty qvalue as 1.0' do
response_with_languages('en,es;q=0.95').body.should.equal('en')
end
- specify 'should set the Content-Language response header' do
+ it 'should set the Content-Language response header' do
headers = response_with_languages('de;q=0.7,dk;q=0.9').headers
headers['Content-Language'].should.equal('dk')
end
- specify 'should pick the language with the highest qvalue' do
+ it 'should pick the language with the highest qvalue' do
response_with_languages('en;q=0.9,es;q=0.95').body.should.equal('es')
end
- specify 'should retain full language codes' do
+ it 'should retain full language codes' do
response_with_languages('en-gb,en-us;q=0.95;en').body.should.equal('en-gb')
end
- specify 'should treat a * as "all other languages"' do
+ it 'should treat a * as "all other languages"' do
response_with_languages('*,en;q=0.5').body.should.equal( I18n.default_locale.to_s )
end
- specify 'should reset the I18n locale after the response' do
+ it 'should reset the I18n locale after the response' do
I18n.locale = 'es'
response_with_languages('en,de;q=0.8')
I18n.locale.should.equal(:es)
View
34 test/spec_rack_mailexceptions.rb
@@ -13,9 +13,9 @@ def test_exception
return boom
end
- context 'Rack::MailExceptions' do
+ describe 'Rack::MailExceptions' do
- setup do
+ before do
@app = lambda { |env| raise TestError, 'Why, I say' }
@env = Rack::MockRequest.env_for("/foo",
'FOO' => 'BAR',
@@ -32,7 +32,7 @@ def test_exception
}
end
- specify 'yields a configuration object to the block when created' do
+ it 'yields a configuration object to the block when created' do
called = false
mailer =
Rack::MailExceptions.new(@app) do |mail|
@@ -45,7 +45,7 @@ def test_exception
called.should.be == true
end
- specify 'generates a TMail object with configured settings' do
+ it 'generates a TMail object with configured settings' do
mailer =
Rack::MailExceptions.new(@app) do |mail|
mail.to 'foo@example.org'
@@ -63,7 +63,7 @@ def test_exception
mail.body.should.be =~ /^\s*THE BODY\s*$/
end
- specify 'catches exceptions raised from app, sends mail, and re-raises' do
+ it 'catches exceptions raised from app, sends mail, and re-raises' do
mailer =
Rack::MailExceptions.new(@app) do |mail|
mail.to 'foo@example.org'
@@ -76,7 +76,7 @@ def test_exception
end
if TEST_SMTP && ! TEST_SMTP.empty?
- specify 'sends mail' do
+ it 'sends mail' do
mailer =
Rack::MailExceptions.new(@app) do |mail|
mail.config.merge! TEST_SMTP
@@ -88,8 +88,8 @@ def test_exception
STDERR.puts 'WARN: Skipping SMTP tests (edit test/mail_settings.rb to enable)'
end
- context 'for tls enabled smtp' do
- setup do
+ describe 'for tls enabled smtp' do
+ before do
@smtp_settings.merge!(TEST_SMTP_TLS)
@mailer =
Rack::MailExceptions.new(@app) do |mail|
@@ -101,7 +101,7 @@ def test_exception
end
describe 'with :enable_starttls_auto set to :auto' do
- specify 'sends mail' do
+ it 'sends mail' do
@mailer.smtp.merge(:enable_starttls_auto => :auto)
lambda { @mailer.call(@env) }.should.raise(TestError)
@env['mail.sent'].should.be true
@@ -109,7 +109,7 @@ def test_exception
end
describe 'with :enable_starttls_auto set to true' do
- specify 'sends mail' do
+ it 'sends mail' do
@mailer.smtp.merge(:enable_starttls_auto => true)
lambda { @mailer.call(@env) }.should.raise(TestError)
@env['mail.sent'].should.be true
@@ -127,7 +127,7 @@ def send_message(*args); end
def self.tls; @@_tls; end
end
- setup do
+ before do
Rack::MailExceptions.class_eval { def service; FakeSMTP; end}
@mailer =
Rack::MailExceptions.new(@app) do |mail|
@@ -138,24 +138,24 @@ def self.tls; @@_tls; end
end
end
- context 'with :enable_starttls_auto unset' do
- specify 'sends mail' do
+ describe 'with :enable_starttls_auto unset' do
+ it 'sends mail' do
@mailer.smtp[:enable_starttls_auto] = nil
lambda { @mailer.call(@env) }.should.raise(TestError)
FakeSMTP.tls.should.be nil
end
end
- context 'with :enable_starttls_auto set to true' do
- specify 'sends mail' do
+ describe 'with :enable_starttls_auto set to true' do
+ it 'sends mail' do
@mailer.smtp[:enable_starttls_auto] = true
lambda { @mailer.call(@env) }.should.raise(TestError)
FakeSMTP.tls.should == true
end
end
- context 'with :enable_starttls_auto set to :auto' do
- specify 'sends mail' do
+ describe 'with :enable_starttls_auto set to :auto' do
+ it 'sends mail' do
@mailer.smtp[:enable_starttls_auto] = :auto
lambda { @mailer.call(@env) }.should.raise(TestError)
FakeSMTP.tls.should == :auto
View
10 test/spec_rack_nested_params.rb
@@ -2,7 +2,7 @@
require 'rack/contrib/nested_params'
require 'rack/methodoverride'
-context Rack::NestedParams do
+describe Rack::NestedParams do
App = lambda { |env| [200, {'Content-Type' => 'text/plain'}, Rack::Request.new(env)] }
@@ -19,24 +19,24 @@ def middleware
Rack::NestedParams.new(App)
end
- specify "should handle requests with POST body Content-Type of application/x-www-form-urlencoded" do
+ it "should handle requests with POST body Content-Type of application/x-www-form-urlencoded" do
req = middleware.call(form_post({'foo[bar][baz]' => 'nested'})).last
req.POST.should.equal({"foo" => { "bar" => { "baz" => "nested" }}})
end
- specify "should not parse requests with other Content-Type" do
+ it "should not parse requests with other Content-Type" do
req = middleware.call(form_post({'foo[bar][baz]' => 'nested'}, 'text/plain')).last
req.POST.should.equal({})
end
- specify "should work even after another middleware already parsed the request" do
+ it "should work even after another middleware already parsed the request" do
app = Rack::MethodOverride.new(middleware)
req = app.call(form_post({'_method' => 'put', 'foo[bar]' => 'nested'})).last
req.POST.should.equal({'_method' => 'put', "foo" => { "bar" => "nested" }})
req.put?.should.equal true
end
- specify "should make first boolean have precedence even after request already parsed" do
+ it "should make first boolean have precedence even after request already parsed" do
app = Rack::MethodOverride.new(middleware)
req = app.call(form_post("foo=1&foo=0")).last
req.POST.should.equal({"foo" => '1'})
View
4 test/spec_rack_not_found.rb
@@ -1,9 +1,9 @@
require 'rack/mock'
require 'rack/contrib/not_found'
-context "Rack::NotFound" do
+describe "Rack::NotFound" do
- specify "should render the file at the given path for all requests" do
+ it "should render the file at the given path for all requests" do
app = Rack::Builder.new do
use Rack::Lint
run Rack::NotFound.new('test/404.html')
View
25 test/spec_rack_post_body_content_type_parser.rb
@@ -3,36 +3,35 @@
begin
require 'rack/contrib/post_body_content_type_parser'
- context "Rack::PostBodyContentTypeParser" do
+ def params_for_request(body, content_type)
+ env = Rack::MockRequest.env_for "/", {:method => "POST", :input => body, "CONTENT_TYPE" => content_type}
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, Rack::Request.new(env).POST] }
+ Rack::PostBodyContentTypeParser.new(app).call(env).last
+ end
+
+ describe "Rack::PostBodyContentTypeParser" do
- specify "should parse 'application/json' requests" do
+ it "should parse 'application/json' requests" do
params = params_for_request '{"key":"value"}', "application/json"
params['key'].should.equal "value"
end
- specify "should parse 'application/json; charset=utf-8' requests" do
+ it "should parse 'application/json; charset=utf-8' requests" do
params = params_for_request '{"key":"value"}', "application/json; charset=utf-8"
params['key'].should.equal "value"
end
- specify "should parse 'application/json' requests with empty body" do
+ it "should parse 'application/json' requests with empty body" do
params = params_for_request "", "application/json"
params.should.equal({})
end
- specify "shouldn't affect form-urlencoded requests" do
+ it "shouldn't affect form-urlencoded requests" do
params = params_for_request("key=value", "application/x-www-form-urlencoded")
params['key'].should.equal "value"
end
- end
-
- def params_for_request(body, content_type)
- env = Rack::MockRequest.env_for "/", {:method => "POST", :input => body, "CONTENT_TYPE" => content_type}
- app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, Rack::Request.new(env).POST] }
- Rack::PostBodyContentTypeParser.new(app).call(env).last
- end
-
+ end
rescue LoadError => e
# Missing dependency JSON, skipping tests.
STDERR.puts "WARN: Skipping Rack::PostBodyContentTypeParser tests (json not installed)"
View
6 test/spec_rack_proctitle.rb
@@ -1,7 +1,7 @@
require 'rack/mock'
require 'rack/contrib/proctitle'
-context "Rack::ProcTitle" do
+describe "Rack::ProcTitle" do
F = ::File
progname = File.basename($0)
@@ -11,12 +11,12 @@ def simple_app(body=['Hello World!'])
lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
end
- specify "should set the process title when created" do
+ it "should set the process title when created" do
Rack::ProcTitle.new(simple_app)
$0.should.equal "#{progname} [#{appname}] init ..."
end
- specify "should set the process title on each request" do
+ it "should set the process title on each request" do
app = Rack::ProcTitle.new(simple_app)
req = Rack::MockRequest.new(app)
10.times { req.get('/hello') }
View
12 test/spec_rack_profiler.rb
@@ -3,34 +3,34 @@
begin
require 'rack/contrib/profiler'
- context 'Rack::Profiler' do
+ describe 'Rack::Profiler' do
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'Oh hai der'] }
request = Rack::MockRequest.env_for("/", :params => "profile=process_time")
- specify 'printer defaults to RubyProf::CallStackPrinter' do
+ it 'printer defaults to RubyProf::CallStackPrinter' do
profiler = Rack::Profiler.new(nil)
profiler.instance_variable_get('@printer').should.equal RubyProf::CallStackPrinter
profiler.instance_variable_get('@times').should.equal 1
end
- specify 'CallStackPrinter has Content-Type test/html' do
+ it 'CallStackPrinter has Content-Type test/html' do
headers = Rack::Profiler.new(app, :printer => :call_stack).call(request)[1]
headers.should.equal "Content-Type"=>"text/html"
end
- specify 'CallTreePrinter has correct headers' do
+ it 'CallTreePrinter has correct headers' do
headers = Rack::Profiler.new(app, :printer => :call_tree).call(request)[1]
headers.should.equal "Content-Disposition"=>"attachment; filename=\"/.process_time.tree\"", "Content-Type"=>"application/octet-stream"
end
- specify 'FlatPrinter and GraphPrinter has Content-Type text/plain' do
+ it 'FlatPrinter and GraphPrinter has Content-Type text/plain' do
%w(flat graph).each do |printer|
headers = Rack::Profiler.new(app, :printer => printer.to_sym).call(request)[1]
headers.should.equal "Content-Type"=>"text/plain"
end
end
- specify 'GraphHtmlPrinter has Content-Type text/html' do
+ it 'GraphHtmlPrinter has Content-Type text/html' do
headers = Rack::Profiler.new(app, :printer => :graph_html).call(request)[1]
headers.should.equal "Content-Type"=>"text/html"
end
View
14 test/spec_rack_relative_redirect.rb
@@ -2,21 +2,21 @@
require 'rack/contrib/relative_redirect'
require 'fileutils'
-context Rack::RelativeRedirect do
+describe Rack::RelativeRedirect do
def request(opts={}, &block)
@def_status = opts[:status] if opts[:status]
@def_location = opts[:location] if opts[:location]
yield Rack::MockRequest.new(Rack::RelativeRedirect.new(@def_app, &opts[:block])).get(opts[:path]||@def_path, opts[:headers]||{})
end
- setup do
+ before do
@def_path = '/path/to/blah'
@def_status = 301
@def_location = '/redirect/to/blah'
@def_app = lambda { |env| [@def_status, {'Location' => @def_location}, [""]]}
end
- specify "should make the location url an absolute url if currently a relative url" do
+ it "should make the location url an absolute url if currently a relative url" do
request do |r|
r.status.should.equal(301)
r.headers['Location'].should.equal('http://example.org/redirect/to/blah')
@@ -27,7 +27,7 @@ def request(opts={}, &block)
end
end
- specify "should use the request path if the relative url is given and doesn't start with a slash" do
+ it "should use the request path if the relative url is given and doesn't start with a slash" do
request(:status=>303, :location=>'redirect/to/blah') do |r|
r.status.should.equal(303)
r.headers['Location'].should.equal('http://example.org/path/to/redirect/to/blah')
@@ -38,7 +38,7 @@ def request(opts={}, &block)
end
end
- specify "should use a given block to make the url absolute" do
+ it "should use a given block to make the url absolute" do
request(:block=>proc{|env, res| "https://example.org"}) do |r|
r.status.should.equal(301)
r.headers['Location'].should.equal('https://example.org/redirect/to/blah')
@@ -49,7 +49,7 @@ def request(opts={}, &block)
end
end
- specify "should not modify the location url unless the response is a redirect" do
+ it "should not modify the location url unless the response is a redirect" do
status = 200
@def_app = lambda { |env| [status, {'Content-Type' => "text/html"}, [""]]}
request do |r|
@@ -64,7 +64,7 @@ def request(opts={}, &block)
end
end
- specify "should not modify the location url if it is already an absolute url" do
+ it "should not modify the location url if it is already an absolute url" do
request(:location=>'https://example.org/') do |r|
r.status.should.equal(301)
r.headers['Location'].should.equal('https://example.org/')
View
36 test/spec_rack_response_cache.rb
@@ -2,39 +2,39 @@
require 'rack/contrib/response_cache'
require 'fileutils'
-context Rack::ResponseCache do
+describe Rack::ResponseCache do
F = ::File
def request(opts={}, &block)
Rack::MockRequest.new(Rack::ResponseCache.new(block||@def_app, opts[:cache]||@cache, &opts[:rc_block])).send(opts[:meth]||:get, opts[:path]||@def_path, opts[:headers]||{})
end
- setup do
+ before do
@cache = {}
@def_disk_cache = F.join(F.dirname(__FILE__), 'response_cache_test_disk_cache')
@def_value = ["rack-response-cache"]
@def_path = '/path/to/blah'
@def_app = lambda { |env| [200, {'Content-Type' => env['CT'] || 'text/html'}, @def_value]}
end
- teardown do
+ after do
FileUtils.rm_rf(@def_disk_cache)
end
- specify "should cache results to disk if cache is a string" do
+ it "should cache results to disk if cache is a string" do
request(:cache=>@def_disk_cache)
F.read(F.join(@def_disk_cache, 'path', 'to', 'blah.html')).should.equal @def_value.first
request(:path=>'/path/3', :cache=>@def_disk_cache)
F.read(F.join(@def_disk_cache, 'path', '3.html')).should.equal @def_value.first
end
- specify "should cache results to given cache if cache is not a string" do
+ it "should cache results to given cache if cache is not a string" do
request
@cache.should.equal('/path/to/blah.html'=>@def_value)
request(:path=>'/path/3')
@cache.should.equal('/path/to/blah.html'=>@def_value, '/path/3.html'=>@def_value)
end
- specify "should not CACHE RESults if request method is not GET" do
+ it "should not CACHE RESults if request method is not GET" do
request(:meth=>:post)
@cache.should.equal({})
request(:meth=>:put)
@@ -43,7 +43,7 @@ def request(opts={}, &block)
@cache.should.equal({})
end
- specify "should not cache results if there is a query string" do
+ it "should not cache results if there is a query string" do
request(:path=>'/path/to/blah?id=1')
@cache.should.equal({})
request(:path=>'/path/to/?id=1')
@@ -52,12 +52,12 @@ def request(opts={}, &block)
@cache.should.equal({})
end
- specify "should cache results if there is an empty query string" do
+ it "should cache results if there is an empty query string" do
request(:path=>'/?')
@cache.should.equal('/index.html'=>@def_value)
end
- specify "should not cache results if the request is not sucessful (status 200)" do
+ it "should not cache results if the request is not sucessful (status 200)" do
request{|env| [404, {'Content-Type' => 'text/html'}, ['']]}
@cache.should.equal({})
request{|env| [500, {'Content-Type' => 'text/html'}, ['']]}
@@ -66,21 +66,21 @@ def request(opts={}, &block)
@cache.should.equal({})
end
- specify "should not cache results if the block returns nil or false" do
+ it "should not cache results if the block returns nil or false" do
request(:rc_block=>proc{false})
@cache.should.equal({})
request(:rc_block=>proc{nil})
@cache.should.equal({})
end
- specify "should cache results to path returned by block" do
+ it "should cache results to path returned by block" do
request(:rc_block=>proc{"1"})
@cache.should.equal("1"=>@def_value)
request(:rc_block=>proc{"2"})
@cache.should.equal("1"=>@def_value, "2"=>@def_value)
end
- specify "should pass the environment and response to the block" do
+ it "should pass the environment and response to the block" do
e, r = nil, nil
request(:rc_block=>proc{|env,res| e, r = env, res; nil})
e['PATH_INFO'].should.equal @def_path
@@ -89,14 +89,14 @@ def request(opts={}, &block)
r.should.equal([200, {"Content-Type"=>"text/html"}, ["rack-response-cache"]])
end
- specify "should unescape the path by default" do
+ it "should unescape the path by default" do
request(:path=>'/path%20with%20spaces')
@cache.should.equal('/path with spaces.html'=>@def_value)
request(:path=>'/path%3chref%3e')
@cache.should.equal('/path with spaces.html'=>@def_value, '/path<href>.html'=>@def_value)
end
- specify "should cache html, css, and xml responses by default" do
+ it "should cache html, css, and xml responses by default" do
request(:path=>'/a')
@cache.should.equal('/a.html'=>@def_value)
request(:path=>'/b', :headers=>{'CT'=>'text/xml'})
@@ -105,7 +105,7 @@ def request(opts={}, &block)
@cache.should.equal('/a.html'=>@def_value, '/b.xml'=>@def_value, '/c.css'=>@def_value)
end
- specify "should cache responses by default with the extension added if not already present" do
+ it "should cache responses by default with the extension added if not already present" do
request(:path=>'/a.html')
@cache.should.equal('/a.html'=>@def_value)
request(:path=>'/b.xml', :headers=>{'CT'=>'text/xml'})
@@ -114,12 +114,12 @@ def request(opts={}, &block)
@cache.should.equal('/a.html'=>@def_value, '/b.xml'=>@def_value, '/c.css'=>@def_value)
end
- specify "should not delete existing extensions" do
+ it "should not delete existing extensions" do
request(:path=>'/d.css', :headers=>{'CT'=>'text/html'})
@cache.should.equal('/d.css.html'=>@def_value)
end
- specify "should cache html responses with empty basename to index.html by default" do
+ it "should cache html responses with empty basename to index.html by default" do
request(:path=>'/')
@cache.should.equal('/index.html'=>@def_value)
request(:path=>'/blah/')
@@ -128,7 +128,7 @@ def request(opts={}, &block)
@cache.should.equal('/index.html'=>@def_value, '/blah/index.html'=>@def_value, '/blah/2/index.html'=>@def_value)
end
- specify "should raise an error if a cache argument is not provided" do
+ it "should raise an error if a cache argument is not provided" do
app = Rack::Builder.new{use Rack::ResponseCache; run lambda { |env| [200, {'Content-Type' => 'text/plain'}, Rack::Request.new(env).POST]}}
proc{Rack::MockRequest.new(app).get('/')}.should.raise(ArgumentError)
end
View
10 test/spec_rack_response_headers.rb
@@ -1,19 +1,19 @@
require 'rack'
require 'rack/contrib/response_headers'
-context "Rack::ResponseHeaders" do
+describe "Rack::ResponseHeaders" do
- specify "yields a HeaderHash of response headers" do
+ it "yields a HeaderHash of response headers" do
orig_headers = {'X-Foo' => 'foo', 'X-Bar' => 'bar'}
app = Proc.new {[200, orig_headers, []]}
middleware = Rack::ResponseHeaders.new(app) do |headers|
- assert_instance_of Rack::Utils::HeaderHash, headers
+ headers.should.be.instance_of(Rack::Utils::HeaderHash)
orig_headers.should == headers
end
middleware.call({})
end
- specify "allows adding headers" do
+ it "allows adding headers" do
app = Proc.new {[200, {'X-Foo' => 'foo'}, []]}
middleware = Rack::ResponseHeaders.new(app) do |headers|
headers['X-Bar'] = 'bar'
@@ -22,7 +22,7 @@
r[1].should == {'X-Foo' => 'foo', 'X-Bar' => 'bar'}
end
- specify "allows deleting headers" do
+ it "allows deleting headers" do
app = Proc.new {[200, {'X-Foo' => 'foo', 'X-Bar' => 'bar'}, []]}
middleware = Rack::ResponseHeaders.new(app) do |headers|
headers.delete('X-Bar')
View
10 test/spec_rack_runtime.rb
@@ -1,26 +1,26 @@
require 'rack/mock'
require 'rack/contrib/runtime'
-context "Rack::Runtime" do
- specify "sets X-Runtime is none is set" do
+describe "Rack::Runtime" do
+ it "sets X-Runtime is none is set" do
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
response = Rack::Runtime.new(app).call({})
response[1]['X-Runtime'].should =~ /[\d\.]+/
end
- specify "does not set the X-Runtime if it is already set" do
+ it "does not set the X-Runtime if it is already set" do
app = lambda { |env| [200, {'Content-Type' => 'text/plain', "X-Runtime" => "foobar"}, "Hello, World!"] }
response = Rack::Runtime.new(app).call({})
response[1]['X-Runtime'].should == "foobar"
end
- specify "should allow a suffix to be set" do
+ it "should allow a suffix to be set" do
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
response = Rack::Runtime.new(app, "Test").call({})
response[1]['X-Runtime-Test'].should =~ /[\d\.]+/
end
- specify "should allow multiple timers to be set" do
+ it "should allow multiple timers to be set" do
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
runtime1 = Rack::Runtime.new(app, "App")
runtime2 = Rack::Runtime.new(runtime1, "All")
View
20 test/spec_rack_sendfile.rb
@@ -1,13 +1,13 @@
require 'rack/mock'
require 'rack/contrib/sendfile'
-context "Rack::File" do
- specify "should respond to #to_path" do
+describe "Rack::File" do
+ it "should respond to #to_path" do
Rack::File.new(Dir.pwd).should.respond_to :to_path
end
end
-context "Rack::Sendfile" do
+describe "Rack::Sendfile" do
def sendfile_body
res = ['Hello World']
def res.to_path ; "/tmp/hello.txt" ; end
@@ -22,7 +22,7 @@ def sendfile_app(body=sendfile_body)
Rack::Sendfile.new(simple_app(body))
end
- setup do
+ before do
@request = Rack::MockRequest.new(sendfile_app)
end
@@ -30,7 +30,7 @@ def request(headers={})
yield @request.get('/', headers)
end
- specify "does nothing when no X-Sendfile-Type header present" do
+ it "does nothing when no X-Sendfile-Type header present" do
request do |response|
response.should.be.ok
response.body.should.equal 'Hello World'
@@ -38,7 +38,7 @@ def request(headers={})
end
end
- specify "sets X-Sendfile response header and discards body" do
+ it "sets X-Sendfile response header and discards body" do
request 'HTTP_X_SENDFILE_TYPE' => 'X-Sendfile' do |response|
response.should.be.ok
response.body.should.be.empty
@@ -46,7 +46,7 @@ def request(headers={})
end
end
- specify "sets X-Lighttpd-Send-File response header and discards body" do
+ it "sets X-Lighttpd-Send-File response header and discards body" do
request 'HTTP_X_SENDFILE_TYPE' => 'X-Lighttpd-Send-File' do |response|
response.should.be.ok
response.body.should.be.empty
@@ -54,7 +54,7 @@ def request(headers={})
end
end
- specify "sets X-Accel-Redirect response header and discards body" do
+ it "sets X-Accel-Redirect response header and discards body" do
headers = {
'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect',
'HTTP_X_ACCEL_MAPPING' => '/tmp/=/foo/bar/'
@@ -66,7 +66,7 @@ def request(headers={})
end
end
- specify 'writes to rack.error when no X-Accel-Mapping is specified' do
+ it 'writes to rack.error when no X-Accel-Mapping is specified' do
request 'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect' do |response|
response.should.be.ok
response.body.should.equal 'Hello World'
@@ -75,7 +75,7 @@ def request(headers={})
end
end
- specify 'does nothing when body does not respond to #to_path' do
+ it 'does nothing when body does not respond to #to_path' do
@request = Rack::MockRequest.new(sendfile_app(['Not a file...']))
request 'HTTP_X_SENDFILE_TYPE' => 'X-Sendfile' do |response|
response.body.should.equal 'Not a file...'
View
38 test/spec_rack_simple_endpoint.rb
@@ -1,84 +1,84 @@
require 'rack'
require 'rack/contrib/simple_endpoint'
-context "Rack::SimpleEndpoint" do
- setup do
+describe "Rack::SimpleEndpoint" do
+ before do
@app = Proc.new { Rack::Response.new {|r| r.write "Downstream app"}.finish }
end
- specify "calls downstream app when no match" do
+ it "calls downstream app when no match" do
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') { 'bar' }
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/baz'))
status.should == 200
body.body.should == ['Downstream app']
end
- specify "calls downstream app when path matches but method does not" do
+ it "calls downstream app when path matches but method does not" do
endpoint = Rack::SimpleEndpoint.new(@app, '/foo' => :get) { 'bar' }
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo', :method => 'post'))
status.should == 200
body.body.should == ['Downstream app']
end
- specify "calls downstream app when path matches but block returns :pass" do
+ it "calls downstream app when path matches but block returns :pass" do
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') { :pass }
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo'))
status.should == 200
body.body.should == ['Downstream app']
end
- specify "returns endpoint response when path matches" do
+ it "returns endpoint response when path matches" do
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') { 'bar' }
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo'))
status.should == 200
body.body.should == ['bar']
end
- specify "returns endpoint response when path and single method requirement match" do
+ it "returns endpoint response when path and single method requirement match" do
endpoint = Rack::SimpleEndpoint.new(@app, '/foo' => :get) { 'bar' }
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo'))
status.should == 200
body.body.should == ['bar']
end
- specify "returns endpoint response when path and one of multiple method requirements match" do
+ it "returns endpoint response when path and one of multiple method requirements match" do
endpoint = Rack::SimpleEndpoint.new(@app, '/foo' => [:get, :post]) { 'bar' }
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo', :method => 'post'))
status.should == 200
body.body.should == ['bar']
end
- specify "returns endpoint response when path matches regex" do
+ it "returns endpoint response when path matches regex" do
endpoint = Rack::SimpleEndpoint.new(@app, /foo/) { 'bar' }
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/bar/foo'))
status.should == 200
body.body.should == ['bar']
end
- specify "block yields Rack::Request and Rack::Response objects" do
+ it "block yields Rack::Request and Rack::Response objects" do
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') do |req, res|
- assert_instance_of ::Rack::Request, req
- assert_instance_of ::Rack::Response, res
+ req.should.be.instance_of(::Rack::Request)
+ res.should.be.instance_of(::Rack::Response)
end
endpoint.call(Rack::MockRequest.env_for('/foo'))
end
- specify "block yields MatchData object when Regex path matcher specified" do
+ it "block yields MatchData object when Regex path matcher specified" do
endpoint = Rack::SimpleEndpoint.new(@app, /foo(.+)/) do |req, res, match|
- assert_instance_of MatchData, match
- assert_equal 'bar', match[1]
+ match.should.be.instance_of(MatchData)
+ match[1].should.equal 'bar'
end
endpoint.call(Rack::MockRequest.env_for('/foobar'))
end
- specify "block does NOT yield MatchData object when String path matcher specified" do
+ it "block does NOT yield MatchData object when String path matcher specified" do
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') do |req, res, match|
- assert_nil match
+ match.should.be.nil
end
endpoint.call(Rack::MockRequest.env_for('/foo'))
end
- specify "response honors headers set in block" do
+ it "response honors headers set in block" do
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') {|req, res| res['X-Foo'] = 'bar'; 'baz' }
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo'))
status.should == 200
@@ -86,7 +86,7 @@
body.body.should == ['baz']
end
- specify "sets Content-Length header" do
+ it "sets Content-Length header" do
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') {|req, res| 'bar' }
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo'))
headers['Content-Length'].should == '3'
View
30 test/spec_rack_static_cache.rb
@@ -11,7 +11,21 @@ def call(env)
describe "Rack::StaticCache" do
- setup do
+ def default_app_request
+ @options = {:urls => ["/statics"], :root => @root}
+ request
+ end
+
+ def configured_app_request
+ @options = {:urls => ["/statics", "/documents*"], :root => @root, :versioning => false, :duration => 2}
+ request
+ end
+
+ def request
+ @request = Rack::MockRequest.new(Rack::StaticCache.new(DummyApp.new, @options))
+ end
+
+ before do
@root = ::File.expand_path(::File.dirname(__FILE__))
end
@@ -73,18 +87,4 @@ def call(env)
res.headers['Expires'].should.not =~ Regexp.new("#{next_next_year}")
end
- def default_app_request
- @options = {:urls => ["/statics"], :root => @root}
- request
- end
-
- def configured_app_request
- @options = {:urls => ["/statics", "/documents*"], :root => @root, :versioning => false, :duration => 2}
- request
- end
-
- def request
- @request = Rack::MockRequest.new(Rack::StaticCache.new(DummyApp.new, @options))
- end
-
end
View
8 test/spec_rack_try_static.rb
@@ -19,7 +19,7 @@ def request(options = {})
end
describe "Rack::TryStatic" do
- context 'when file cannot be found' do
+ describe 'when file cannot be found' do
it 'should call call app' do
res = request(build_options(:try => ['html'])).get('/documents')
res.should.be.ok
@@ -27,7 +27,7 @@ def request(options = {})
end
end
- context 'when file can be found' do
+ describe 'when file can be found' do
it 'should serve first found' do
res = request(build_options(:try => ['.html', '/index.html', '/index.htm'])).get('/documents')
res.should.be.ok
@@ -35,7 +35,7 @@ def request(options = {})
end
end
- context 'when path_info maps directly to file' do
+ describe 'when path_info maps directly to file' do
it 'should serve existing' do
res = request(build_options(:try => ['/index.html'])).get('/documents/existing.html')
res.should.be.ok
@@ -43,7 +43,7 @@ def request(options = {})
end
end
- context 'when sharing options' do
+ describe 'when sharing options' do
it 'should not mutate given options' do
org_options = build_options :try => ['/index.html']
given_options = org_options.dup
Please sign in to comment.
Something went wrong with that request. Please try again.