Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Models Named Test* cause test failures

#1776

We do A/B tests and multivariate testing in my rails app and so we have some models named Test*

This is causing some unfortunate testing errors:

$ rails -v Rails 2.1.1

$ rails foo $ cd foo $ ./script/generate model test_something $ rake db:migrate $ rake test

1) Error:

test_somethings(ActionController::TestCase): ArgumentError: wrong number of arguments (0 for 1)

  /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/test_case.rb:73:in `initialize'
  /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/test_case.rb:73:in `new'
  /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/test_case.rb:73:in `setup_controller_request_and_response'
  /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:173:in `send'
  /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:173:in `evaluate_method'
  /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:161:in `call'
  /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:90:in `run'
  /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:90:in `each'
  /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:90:in `send'
  /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:90:in `run'
  /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:272:in `run_callbacks'
  /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:65:in `run'

6 tests, 1 assertions, 0 failures, 1 errors

Reported by Chris · January 17th, 2009 @ 06:22 PM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Matt Jones
    Matt Jones

    This is a gotcha with the fixture loading; if you remove test_somethings.yml from fixtures/ the test will pass.

    The conflict comes from the accessor method that AR generates; it would be test_somethings(:fixture_name) for this case. Unfortunately, then Test::Unit tries to run that function...

    January 17th, 2009 @ 09:01 PM

  2. Michael Koziarski
    Michael Koziarski
    • State changed from new to wontfix

    This is an inherent limitation with test/unit. The fixture accessors are treated as test methods.

    The only option short of renaming all those models is to not use the fixtures as mentioned by matt.

    January 17th, 2009 @ 11:31 PM