Sha256: b46dbfce70c7ad86c1bb454815fc0114145114e451216f5aa9cdaa7edc1c37a7
Contents?: true
Size: 1.91 KB
Versions: 2
Compression:
Stored size: 1.91 KB
Contents
require 'ostruct' require 'test/unit' require 'test/unit/assertions' require 'rexml/document' require 'glue' require 'nitro/test/context' module Test::Unit class TestCase include Nitro def reset_context @context_config = OpenStruct.new( :dispatcher => Nitro::Dispatcher.new(Nitro::Server.map) ) @context = Nitro::Context.new(@context_config) 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 =~ /^\// reset_context unless @context context = @context if @last_response_cookies @last_response_cookies.each do |cookie| context.cookies.merge! cookie.name => cookie.value end end 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.headers['REMOTE_ADDR'] ||= '127.0.0.1' if ((:get == options[:method]) and (options[:params])) context.headers['QUERY_STRING'] = options[:params].collect {|k,v| "#{k}=#{v}"}.join('&') end context.cookies.merge! options[:cookies] if options[:cookies] context.session.merge! options[:session] if options[:session] context.render(context.path) @last_response_cookies = context.response_cookies 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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.41.0 | lib/nitro/test/testcase.rb |
nitro-0.40.0 | lib/nitro/test/testcase.rb |