I''m using template components to modularize an application I''m
working
on and am really happy with the way it''s going. Unfortunately, all my
attempts at writing functional tests for them fail. Trying to duplicate
my normal controller tests I have:
require File.dirname(__FILE__) + ''/../test_helper''
require File.dirname(__FILE__) + ''news_controller''
# Re-raise errors caught by the controller.
class NewsController; def rescue_action(e) raise e end; end
class NewsControllerTest < Test::Unit::TestCase
def setup
@controller = NewsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
# Replace this with your real tests.
def test_content
get :content
assert_response :success
assert_rendered_file "content"
end
end
But running that gives me:
1) Error:
test_content(NewsControllerTest):
NoMethodError: undefined method `controller_path'' for
NewsController:Class
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/test_process.rb:295:in
`process''
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/test_process.rb:307:in
`get''
news_controller_test.rb:16:in `test_content''
So, I''m guessing I can''t use get() with components? Any
advice?
Thanks,
Mike
Mike Evans wrote:> I''m using template components to modularize an application I''m working > on and am really happy with the way it''s going. Unfortunately, all my > attempts at writing functional tests for them fail. Trying to > duplicate my normal controller tests I have: > > require File.dirname(__FILE__) + ''/../test_helper'' > require File.dirname(__FILE__) + ''news_controller''Errr... that second line should be: require ''news_controller''
Hi Mike I''ve been trying the same thing - testing my Component, but receiving errors all over - finally got it working, so here''s my finding(s): * The testfile goes in /components/<componentname>/test * The testfile is modified (basically prepending the componentname in various places: require File.dirname(__FILE__) + ''/../../test/test_helper'' require ''<componentname>/<controllername>_controller'' # Re-raise errors caught by the controller. class <componentname>::<controllername>Controller; def rescue_action(e) raise e end; end class <componentname>::<controllername>ControllerTest < Test::Unit::TestCase ... @controller = <componentname>::<controllername>Controller.new Hope that helps, /CS -- Posted via http://www.ruby-forum.com/.
Whoops:> require File.dirname(__FILE__) + ''/../../test/test_helper'' > require ''<componentname>/<controllername>_controller''require File.dirname(__FILE__) + ''/../../../test/test_helper'' - need an extra up-level there to actually *work* :-) /CS -- Posted via http://www.ruby-forum.com/.