1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00
sinatra/rack-protection/spec/support/spec_helpers.rb
2014-09-03 19:25:20 +02:00

36 lines
No EOL
771 B
Ruby

require 'forwardable'
module SpecHelpers
extend Forwardable
def_delegators :last_response, :body, :headers, :status, :errors
def_delegators :current_session, :env_for
attr_writer :app
def app
@app ||= nil
@app || mock_app(DummyApp)
end
def mock_app(app = nil, &block)
app = block if app.nil? and block.arity == 1
if app
klass = described_class
mock_app do
use Rack::Head
use(Rack::Config) { |e| e['rack.session'] ||= {}}
use klass
run app
end
else
@app = Rack::Lint.new Rack::Builder.new(&block).to_app
end
end
def with_headers(headers)
proc { [200, {'Content-Type' => 'text/plain'}.merge(headers), ['ok']] }
end
def env
Thread.current[:last_env]
end
end