new do ... end.new syntax creates an instance of an anonymous class
with the provided class definition. A more verbose, named, equivalent would be:
class MyTestController
# class definition...
end
@controller = MyTestController.new
??? Sometimes, dependencies are complicated enough so as to require actually loading
a full framework. This is the case with the SSL Requirement plugin, which
actually loads ActionController and sets up a controller for testing purposes.
First, the code loads ActionController (this either requires RUBYOPT="rubygems" and
a suitable gem version of ActionController, or setting the ACTIONCONTROLLER_PATH
environment variable to a copy of the ActionController source):
begin
require 'action_controller'
rescue LoadError
if ENV['ACTIONCONTROLLER_PATH'].nil?
abort <
Please set the ACTIONCONTROLLER_PATH environment variable to the directory
containing the action_controller.rb file.
MSG
else
$LOAD_PATH.unshift << ENV['ACTIONCONTROLLER_PATH']
begin
require 'action_controller'
rescue LoadError
abort "ActionController could not be found."
end
end
end
Then, the test code loads ActionController??™s test_process, which affords access
to ActionController::TestRequest and ActionController::TestResponse. After
that, logging is silenced and routes are reloaded:
require 'action_controller/test_process'
require 'test/unit'
require "#{File.
Pages:
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146