Opening classes in tests makes rake gone wild

8 views
Skip to first unread message

Michel Pigassou

unread,
Aug 26, 2011, 5:57:08 AM8/26/11
to rubyonra...@googlegroups.com
Hi!

I've discovered that when I reopen classes to return another value, everything works fine when launching the test manually but when I use rake test, the value set reopening the class impacts other tests.

Do you know why?

PS: yeah I know I can use mocha ;)

Frederick Cheung

unread,
Aug 26, 2011, 7:49:22 AM8/26/11
to Ruby on Rails: Talk


On Aug 26, 10:57 am, Michel Pigassou <dag...@gmail.com> wrote:
> Hi!
>
> I've discovered that when I reopen classes to return another value,
> everything works fine when launching the test manually but when I use rake
> test, the value set reopening the class impacts other tests.
>

Tests should leave the environment unchanged. That's why (for example)
transactions are used so that objects created in one test aren't there
when the next test runs. Your test framework doesn't know how to undo
whatever you did when you reopened the class, so the change persists.
If you absolutely have to do it this way, you'll need to undo the
change once the test that needs it is complete.

Fred

Michel Pigassou

unread,
Aug 26, 2011, 9:32:13 AM8/26/11
to rubyonra...@googlegroups.com
I hear you Frederick. But I forgot one detail: my problem is that a class reopen in a test file impacts tests in another test file.
I thought rake would reload every class between each test file.

Frederick Cheung

unread,
Aug 26, 2011, 11:10:28 AM8/26/11
to Ruby on Rails: Talk
As you have discovered, it doesn't (would probably be prohibitively
slow)

Fred
Reply all
Reply to author
Forward
0 new messages