Sha256: 90dcd4b8094204871dfc7d3befeabffc684cab155a796a785cb607ea300ebbb0

Contents?: true

Size: 1.73 KB

Versions: 16

Compression:

Stored size: 1.73 KB

Contents

$:.unshift(File.expand_path("../lib", File.dirname(__FILE__)))

require "rubygems"

if ENV['COVERAGE']
  require 'coverage'
  require 'simplecov'

  def SimpleCov.roda_coverage(opts = {})
    start do
      add_filter "/spec/"
      add_group('Missing'){|src| src.covered_percent < 100}
      add_group('Covered'){|src| src.covered_percent == 100}
      yield self if block_given?
    end
  end

  ENV.delete('COVERAGE')
  SimpleCov.roda_coverage
end

require "roda"
require "stringio"

unless defined?(RSPEC_EXAMPLE_GROUP)
  if defined?(RSpec)
    require 'rspec/version'
    if RSpec::Version::STRING >= '2.11.0'
      RSpec.configure do |config|
        config.expect_with :rspec do |c|
          c.syntax = :should
        end
        config.mock_with :rspec do |c|
          c.syntax = :should
        end
      end
    end
    RSPEC_EXAMPLE_GROUP = RSpec::Core::ExampleGroup
  else
    RSPEC_EXAMPLE_GROUP = Spec::Example::ExampleGroup
  end
end

class RSPEC_EXAMPLE_GROUP
  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

16 entries across 16 versions & 2 rubygems

Version Path
roda-1.2.0 spec/spec_helper.rb
roda-1.1.0 spec/spec_helper.rb
roda-cj-1.0.5 spec/spec_helper.rb
roda-cj-1.0.4 spec/spec_helper.rb
roda-cj-1.0.3 spec/spec_helper.rb
roda-cj-1.0.2 spec/spec_helper.rb
roda-cj-1.0.1 spec/spec_helper.rb
roda-cj-1.0.0 spec/spec_helper.rb
roda-1.0.0 spec/spec_helper.rb
roda-cj-0.9.6 spec/spec_helper.rb
roda-cj-0.9.5 spec/spec_helper.rb
roda-cj-0.9.4 spec/spec_helper.rb
roda-cj-0.9.3 spec/spec_helper.rb
roda-cj-0.9.2 spec/spec_helper.rb
roda-cj-0.9.1 spec/spec_helper.rb
roda-0.9.0 spec/spec_helper.rb