Opening classes in tests makes rake gone wild

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 :wink:

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

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.

As you have discovered, it doesn't (would probably be prohibitively
slow)

Fred