This project is archived and is in readonly mode.

#5061 ✓resolved

ActionView::TestCase does not initialize helpers contra actual ActionView Behaviour

Reported by hjdivad | July 7th, 2010 @ 03:16 PM

Steps to reproduce

# create a new rails app
rails new rails-helper-init && cd rails-helper-init

# create a resource to play with
rails generate scaffold Ninja

# modify the helper so it has an initializer
echo "module NinjasHelper
  attr_accessor   :initialized_count
  def initialize( *args, &block )
    super *args, &block

    @initialized_count    ||= 0
    @initialized_count    +=  1
end" > app/helpers/ninjas_helper.rb

# create a test that checks the helper is initialized
echo "require 'test_helper'

class NinjasHelperTest < ActionView::TestCase
  def test_initialization_count
    assert_equal initialized_count, 1
end" > test/unit/helpers/ninjas_helper_test.rb

# run migrations
rake db:migrate

# run tests
rake test:units

Expected Behaviour

The above helper unit test should pass.

Actual Behaviour

rake test:units
(in /tmp/rails-helper-init)
Loaded suite /home/davidjh/.rvm/gems/ree-1.8.7-2010.01/gems/rake-0.8.7/lib/rake/rake_test_loader
Finished in 0.013791 seconds.

  1) Failure:
test_initialization_count(NinjasHelperTest) [/test/unit/helpers/ninjas_helper_test.rb:5]:
<nil> expected but was

2 tests, 2 assertions, 1 failures, 0 errors
rake aborted!


This is strictly an issue with testing: the view is initialized properly
(presumably because the initializer of the class that mixes it in calls super) when running rails.


[davidjh@nyx (; ree-1.8.7-2010.01)] /tmp/rails-helper-init
$ rails --version
Rails 3.0.0.beta4
[davidjh@nyx (; ree-1.8.7-2010.01)] /tmp/rails-helper-init
$ ruby --version
ruby 1.8.7 (2009-12-24 patchlevel 248) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2010.01

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=""></a>

Referenced by