Forum: Ruby on Rails testing template 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.
matthew clark (Guest)
on 2006-01-14 14:02
(Received via mailing list)
Hi,

I'm plowing through the template section of "Agile Rails", specifically
the
stuff starting on P. 364.  What is a good strategy for testing
components?

My initial thought is to mimic the Rails application "test" directory.
No
problem.

Next copy the setup method, and set it up like so -

class SidebarControllerTest < Test::Unit::TestCase
  def setup
    @controller = Navigation::Sidebar.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

  def test_setup
     assert true
  end
end

Nope, that throws an error that makes me think I am headed in the wrong
direction-

  1) Error:
test_get_menu(SidebarControllerTest):
NoMethodError: undefined method `new' for
Navigation::Sidebar:Dependencies::LoadingModule
    functional/sidebarTest.rb:9:in `setup_without_fixtures'
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:523:in
`setup'
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:521:in
`setup'

Here is the controller if that is of interest (basically copied out of
the
book)

class Navigation::SidebarController < ActionController::Base
  uses_component_template_root
  Link = Struct.new(:name, :url)
  def self.find(*ignored)
    [Link.new("people","/person"),
      Link.new("home","/")]
  end

  def menu
    @links = self.class.find(:all)
    render(:layout => false)
  end
end

So, what is a good way to test components?  The one requirment I see is
that
the tests should live inside of the components directory.

matt
This topic is locked and can not be replied to.