Sha256: 5d599d02687f71bc7b37c68f46a823da8704a53a58f9d66f70d3d0ea5da474d9

Contents?: true

Size: 1.02 KB

Versions: 9

Compression:

Stored size: 1.02 KB

Contents

lib = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'roda'
require 'roda/component'
require_relative 'dummy/app'

before do
  @app = TestApp
end

after do
  @app = nil
end

module Kernel
  private

  def app(type=nil, &block)
    case type
    when :new
      @app = _app{route(&block)}
    when :bare
      @app = _app(&block)
    when Symbol
      @app = _app do
        plugin type
        route(&block)
      end
    else
      @app ||= _app{route(&block)}
    end
  end

  def req(path='/', env={})
    if path.is_a?(Hash)
      env = path
    else
      env['PATH_INFO'] = path
    end

    env = {"REQUEST_METHOD" => "GET", "PATH_INFO" => "/", "SCRIPT_NAME" => ""}.merge(env)
    @app.call(env)
  end

  def status(path='/', env={})
    req(path, env)[0]
  end

  def header(name, path='/', env={})
    req(path, env)[1][name]
  end

  def body(path='/', env={})
    req(path, env)[2].join
  end

  def _app(&block)
    c = Class.new(Roda)
    c.class_eval(&block)
    c
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
roda-component-0.0.10 test/helper.rb
roda-component-0.0.9 test/helper.rb
roda-component-0.0.8 test/helper.rb
roda-component-0.0.7 test/helper.rb
roda-component-0.0.6 test/helper.rb
roda-component-0.0.5 test/helper.rb
roda-component-0.0.4 test/helper.rb
roda-component-0.0.3 test/helper.rb
roda-component-0.0.2 test/helper.rb