Sha256: 8eeb437beb8b7dc2123cfcffb9bbadf2f8fc4ded44cc6643b9eb8b837edcb65e

Contents?: true

Size: 1.36 KB

Versions: 7

Compression:

Stored size: 1.36 KB

Contents

require 'test/unit'
require 'test/unit/assertions'
require 'rexml/document'

require 'glue'
require 'nitro/test/context'

module Test::Unit
  
class TestCase
  include Nitro

  def controller(klass)
    @server = Server.run(klass)
  end

  # Send a request to the controller. Alternatively you can use
  # the request method helpers (get, post, ...)
  #
  # === Options
  #
  # :uri, :method, :headers/:env, :params, :session
  
  def process(options = {})
    unless options.is_a? Hash
      options = { :uri => options.to_s }
    end

    uri = options[:uri]
    uri = "/#{uri}" unless uri =~ /^\//
   
    context = @context = Context.new(@server)

    context.params = options[:params] || {}
    context.headers = options[:headers] || options[:env] || {}
    context.headers['REQUEST_URI'] = uri
    context.headers['REQUEST_METHOD'] = options[:method].to_s.upcase
    context.cookies = options[:cookies]
    context.session = options[:session] if options[:session]
    
    context.render(context.path)
    
    return context.body
  end

  #--
  # Compile some helpers.
  #++
  
  for m in [:get, :post, :put, :delete, :head]
    eval %{
      def #{m}(options = {})
        unless options.is_a? Hash
          options = { :uri => options.to_s }
        end
        options[:method] = :#{m}
        process(options)
      end 
    }
  end

end

end

# * George Moschovitis <gm@navel.gr>

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nitro-0.22.0 lib/nitro/test/testcase.rb
nitro-0.23.0 lib/nitro/test/testcase.rb
nitro-0.24.0 lib/nitro/test/testcase.rb
nitro-0.25.0 lib/nitro/test/testcase.rb
nitro-0.26.0 lib/nitro/test/testcase.rb
nitro-0.27.0 lib/nitro/test/testcase.rb
nitro-0.28.0 lib/nitro/test/testcase.rb