Sha256: 18619c751524086e0607d0ac764ac446725bb8295d8e00414bab2525d49639f3

Contents?: true

Size: 1.53 KB

Versions: 12

Compression:

Stored size: 1.53 KB

Contents

ENV['PADRINO_ENV'] = 'test'
PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT

require 'rubygems'
require 'padrino-core'
require 'test/unit'
require 'rack/test'
require 'rack'
require 'shoulda'

module Kernel
  # Silences the output by redirecting to stringIO
  # silence_logger { ...commands... } => "...output..."
  def silence_logger(&block)
    $stdout = log_buffer = StringIO.new
    block.call
    $stdout = STDOUT
    log_buffer.string
  end
  alias :silence_stdout :silence_logger

  def silence_warnings
    old_verbose, $VERBOSE = $VERBOSE, nil
    yield
  ensure
    $VERBOSE = old_verbose
  end unless respond_to?(:silence_warnings)

end

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

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

  # 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=Padrino::Application, &block)
    @app = Sinatra.new(base, &block)
  end

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

  # Asserts that a file matches the pattern
  def assert_match_in_file(pattern, file)
    assert File.exist?(file), "File '#{file}' does not exist!"
    assert_match pattern, File.read(file)
  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(name, *args, &block)
    end
  end

  alias :response :last_response
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
padrino-core-0.9.7 test/helper.rb
padrino-core-0.9.6 test/helper.rb
padrino-core-0.9.5 test/helper.rb
padrino-core-0.9.4 test/helper.rb
padrino-core-0.9.3 test/helper.rb
padrino-core-0.9.2 test/helper.rb
padrino-core-0.9.1 test/helper.rb
padrino-core-0.9.0 test/helper.rb
padrino-core-0.8.5 test/helper.rb
padrino-core-0.8.4 test/helper.rb
padrino-core-0.8.3 test/helper.rb
padrino-core-0.8.2 test/helper.rb