mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
f10e571f4d
We use minitest for Sinatra's test suite but we weren't using its rake task. I've updated the Rakefile to require and use Minitest default rake task to simplify. Another change is to rename the `helper.rb` file to `test_helper.rb` because I think that name is used more in the community and require it directly without calling `File.expand_path`
45 lines
1 KiB
Ruby
45 lines
1 KiB
Ruby
require_relative 'test_helper'
|
|
require 'rack'
|
|
|
|
class RackTest < Minitest::Test
|
|
setup do
|
|
@foo = Sinatra.new { get('/foo') { 'foo' }}
|
|
@bar = Sinatra.new { get('/bar') { 'bar' }}
|
|
end
|
|
|
|
def build(*middleware)
|
|
endpoint = middleware.pop
|
|
@app = Rack::Builder.app do
|
|
middleware.each { |m| use m }
|
|
run endpoint
|
|
end
|
|
end
|
|
|
|
def check(*middleware)
|
|
build(*middleware)
|
|
assert get('/foo').ok?
|
|
assert_body 'foo'
|
|
assert get('/bar').ok?
|
|
assert_body 'bar'
|
|
end
|
|
|
|
it 'works as middleware in front of Rack::Lock, with lock enabled' do
|
|
@foo.enable :lock
|
|
check(@foo, Rack::Lock, @bar)
|
|
end
|
|
|
|
it 'works as middleware behind Rack::Lock, with lock enabled' do
|
|
@foo.enable :lock
|
|
check(Rack::Lock, @foo, @bar)
|
|
end
|
|
|
|
it 'works as middleware in front of Rack::Lock, with lock disabled' do
|
|
@foo.disable :lock
|
|
check(@foo, Rack::Lock, @bar)
|
|
end
|
|
|
|
it 'works as middleware behind Rack::Lock, with lock disabled' do
|
|
@foo.disable :lock
|
|
check(Rack::Lock, @foo, @bar)
|
|
end
|
|
end
|