Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10379 (reopened defect)

Opened 5 months ago

Last modified 3 months ago

[PATCH] Avoid missing fixture setup if a TestCase class is loaded multiple times

Reported by: brynary Assigned to: core
Priority: low Milestone: 2.1
Component: ActiveRecord Version: edge
Severity: minor Keywords: testcase fixtures
Cc: thewoolleyman@gmail.com

Description

If a TestCase using fixtures with it's own setup method is loaded multiple times by Ruby, the second load will cause it to loose its hook to call the fixture setup code. The result is that the first time the test access fixtures, it will blow up because fixtures have not been setup.

This patch (with tests) causes the fixtures TestCase hook to stay active regardless of how many times a TestCase subclass may be loaded. Burned a whole day to track down this bug, and while it is an edge case, this will ensure no one else has to do that in the future.

Attachments

make_fixture_setup_support_testcase_classes_loaded_multiple_times.patch (2.6 kB) - added by brynary on 12/10/07 20:01:40.
make_subclassed_testcase_and_testcase_loaded_multiple_times_both_work.patch (2.9 kB) - added by kasatani on 12/20/07 02:19:52.

Change History

12/05/07 20:23:00 changed by jbarnette

+1 That loading code is scary.

12/05/07 20:47:53 changed by brynary

BTW, apologies for the griping about the time spent working on this in the original ticket. Realize now that it was rather impolite.

12/05/07 20:53:06 changed by joshknowles

+1

12/10/07 20:01:40 changed by brynary

  • attachment make_fixture_setup_support_testcase_classes_loaded_multiple_times.patch added.

12/10/07 20:04:01 changed by wilson

  • keywords set to verified.
  • priority changed from normal to low.
  • severity changed from normal to minor.

+1

12/10/07 20:34:30 changed by marcel

Just out of curiosity, what in your case was causing your test case to be loaded twice?

12/10/07 21:38:27 changed by brynary

The specific case I saw was when using RSpec's test interop mode and running the tests via rake. The first load was by rake, the second load was by RSpec. In addition to this patch, I'm working with the RSpec guys to see how we can ensure there is no double load in that situation.

Certainly realize Rails does not officially support RSpec, but given the limitations of Ruby's 1.8 require statement, a double load is possible in other situations, so it would be good to get this patch to protect against that.

12/15/07 01:23:09 changed by rick

  • status changed from new to closed.
  • resolution set to fixed.

(In [8392]) Make the Fixtures Test::Unit enhancements more supporting for double-loaded test cases. Closes #10379 [brynary]

12/20/07 00:33:55 changed by brynary

  • keywords deleted.
  • status changed from closed to reopened.
  • resolution deleted.

Reopened by r8392

12/20/07 02:19:52 changed by kasatani

  • attachment make_subclassed_testcase_and_testcase_loaded_multiple_times_both_work.patch added.

12/20/07 02:21:27 changed by kasatani

I've attached a patch that passes both tests described in #10568 and this issue. It's a combination of the original patch and the patch attached to #10536.

12/20/07 11:54:48 changed by joergd

+1

01/30/08 16:13:52 changed by thewoolleyman

  • keywords set to verified.

re-marking this as verified, as it was previously verified but re-opened.

02/02/08 03:05:15 changed by bitsweat

  • keywords changed from verified to testcase fixtures.
  • milestone changed from 2.x to 2.1.

Is this still an issue on trunk, which uses declared setup and teardown methods now?

02/02/08 18:23:44 changed by thewoolleyman

  • cc set to thewoolleyman@gmail.com.

Looks like the recent changes in setup_and_teardown.rb could have fixed this, but the testcase is still failing. Also, things have moved around some and the patch is out of date. The original poster should review...

02/05/08 08:33:27 changed by jjonphl

I think we're going at this the wrong way. It will be simpler if we just use hardmock project's before_setup and after_teardown hooks (http://hardmock.rubyforge.org/svn/trunk/lib/test_unit_before_after.rb). The current technique cannot handle anything beyond the 1st inheritance.

(follow-up: ↓ 16 ) 02/06/08 01:14:25 changed by bitsweat

jjonphi, are you referring to the declared setup and teardown methods? They look pretty much exactly like this plugin.

(in reply to: ↑ 15 ) 02/06/08 12:30:55 changed by jjonphl

Replying to bitsweat:

jjonphi, are you referring to the declared setup and teardown methods? They look pretty much exactly like this plugin.

bitsweat, I'm sorry I thought from the attached patches that it was still the method_added stuff. I saw your commit (r8570). I'll check it out. Thanks