File: helper.rb

package info (click to toggle)
ruby-rack-accept 0.4.5-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 188 kB
  • sloc: ruby: 630; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 885 bytes parent folder | download | duplicates (4)
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
ENV['RACK_ENV'] = 'test'

begin
  require 'rack'
rescue LoadError
  require 'rubygems'
  require 'rack'
end

testdir = File.dirname(__FILE__)
$LOAD_PATH.unshift(testdir) unless $LOAD_PATH.include?(testdir)

libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)

require 'test/unit'
require 'rack/accept'

class Test::Unit::TestCase
  attr_reader :context
  attr_reader :response

  def status
    @response && @response.status
  end

  def request(env={}, method='GET', uri='/')
    @context = Rack::Accept.new(fake_app)
    yield @context if block_given?
    mock_request = Rack::MockRequest.new(@context)
    @response = mock_request.request(method.to_s.upcase, uri, env)
    @response
  end

  def fake_app(status=200, headers={}, body=[])
    lambda {|env| Rack::Response.new(body, status, headers).finish }
  end
end