Class: Test::Unit::TestCase

Inherits:
Object
  • Object
show all
Includes:
Nitro
Defined in:
lib/nitro/test/testcase.rb

Constant Summary

Constants included from Nitro

Nitro::ConsoleAdapter, Nitro::ElementCompiler, Nitro::LibPath, Nitro::Run, Nitro::Version

Constants included from Glue

Glue::WebImage

Instance Method Summary collapse

Methods included from Nitro

live?, mode, run

Instance Method Details

#process(options = {}) ⇒ Object

Send a request to the controller. Alternatively you can use the request method helpers (get, post, …)

Options

:uri, :method, :headers/:env, :params, :session



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nitro/test/testcase.rb', line 29

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

#reset_contextObject



15
16
17
18
19
20
# File 'lib/nitro/test/testcase.rb', line 15

def reset_context
  @context_config = OpenStruct.new(
    :dispatcher => Nitro::Dispatcher.new(Nitro::Server.map)
  )
  @context = Nitro::Context.new(@context_config)
end