This project is archived and is in readonly mode.

#4697 ✓resolved
David Chelimsky

Let test authors set up controller_path in ActionView::TestCase without using stubs

Reported by David Chelimsky | May 26th, 2010 @ 02:13 AM

AV::TestCase requires test authors to stub TestController.controller_path if the template being rendered in the test renders any partials. This is evidenced in rails' own tests:

# in actionpack/test/template/test_case_test.rb
test "is able to render partials from templates and also use instance variables" do
  TestController.stubs(:controller_path).returns('test')

  @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
  assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
end

This patch makes it so you can just assign controller_path directly on the controller instance, and it handles setting it on the class.

http://github.com/dchelimsky/rails/commit/c725d23a535d2a3dd27c8c979...

The result is a test method like this:

# in actionpack/test/template/test_case_test.rb
test "is able to render partials from templates and also use instance variables" do
  controller.controller_path = 'test'

  @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
  assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
end

This removes the dependency on a stub framework, and makes it easier for extension libraries (like rspec-rails) to set it implicitly without having to clean up after each test.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>