Sha256: 2bbc4d938d571a3d07bdef31b77fa636d494698d2d9e752a52dfdb66465d8b7b

Contents?: true

Size: 1.56 KB

Versions: 32

Compression:

Stored size: 1.56 KB

Contents

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 'contest'
require 'rack/test'
require 'sinatra/base'

class Sinatra::Base
  # Allow assertions in request context
  include Test::Unit::Assertions
end

Sinatra::Base.set :environment, :test

class Test::Unit::TestCase
  include Rack::Test::Methods

  class << self
    alias_method :it, :test
  end

  alias_method :response, :last_response

  setup do
    Sinatra::Base.set :environment, :test
  end

  # Sets up a Sinatra::Base subclass defined with the block
  # given. Used in setup or individual spec methods to establish
  # the application.
  def mock_app(base=Sinatra::Base, &block)
    @app = Sinatra.new(base, &block)
  end

  def app
    Rack::Lint.new(@app)
  end

  def body
    response.body.to_s
  end

  # Delegate other missing methods to response.
  def method_missing(name, *args, &block)
    if response && response.respond_to?(name)
      response.send(name, *args, &block)
    else
      super
    end
  end

  # Also check response since we delegate there.
  def respond_to?(symbol, include_private=false)
    super || (response && response.respond_to?(symbol, include_private))
  end

  # Do not output warnings for the duration of the block.
  def silence_warnings
    $VERBOSE, v = nil, $VERBOSE
    yield
  ensure
    $VERBOSE = v
  end
end

Version data entries

32 entries across 31 versions & 9 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sinatra-1.0/test/helper.rb
adamwiggins-sinatra-0.10.1 test/helper.rb
sinatra-sinatra-0.10.0 test/helper.rb
sinatra-sinatra-0.10.1 test/helper.rb
sinatra-sinatra-0.9.2 test/helper.rb
sinatra-base-1.0 test/helper.rb
sinatra-1.0 test/helper.rb
sinatra-1.0.b test/helper.rb
sinatra-0.9.6 test/helper.rb
sinatra-0.9.5 test/helper.rb
sinatra-bundles-0.1.2 vendor/gems/sinatra-0.10.1/test/helper.rb
akamai_bookmarklet-0.1.2 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/test/helper.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/sinatra-0.9.4/test/helper.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/sinatra-1.0.a/test/helper.rb
akamai_bookmarklet-0.1.1 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/test/helper.rb
akamai_bookmarklet-0.1.0 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/test/helper.rb
sinatra-1.0.a test/helper.rb
sinatra-bundles-0.1.1 vendor/gems/sinatra-0.10.1/test/helper.rb
sinatra-bundles-0.1.0 vendor/gems/sinatra-0.10.1/test/helper.rb
sinatra-bundles-0.0.2 vendor/gems/sinatra-0.10.1/test/helper.rb