Forum: Ruby on Rails Testing components

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2c17b677625ca6499a2d9ea2ca724873?d=identicon&s=25 Mike Evans (Guest)
on 2006-02-01 22:39
(Received via mailing list)
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
2c17b677625ca6499a2d9ea2ca724873?d=identicon&s=25 Mike Evans (Guest)
on 2006-02-02 00:50
(Received via mailing list)
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'
3c220592e577efd82a17eaa0e2874be5?d=identicon&s=25 Chriztian Steinmeier (greystate)
on 2006-02-21 02:28
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
3c220592e577efd82a17eaa0e2874be5?d=identicon&s=25 Chriztian Steinmeier (greystate)
on 2006-02-21 08:42
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
This topic is locked and can not be replied to.