/
spec_helper.rb
45 lines (38 loc) · 936 Bytes
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'rubygems'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'rack/test'
require 'rack/policy'
module DummyApp
def self.call(env)
Thread.current[:last_env] = env
[200, {'Content-Type' => 'text/plain'}, ['ok']]
end
end
module TestHelpers
def app
@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 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
end
RSpec.configure do |config|
config.order = :rand
config.expect_with :rspec, :stdlib
config.include Rack::Test::Methods
config.include TestHelpers
end