> I'll have to check on this, but I don't think that reload! reloads the
> whole environment -- which is probably why you don't get the 10-second
It doesn't reload stuff like route changes or changes to environmnet.rb,
but that's okay. It does reload stuff like changes to any classes in
app/*.
> If your old test has side effects (such as DB operations!) that are not
> cleaned up, then it will influence the new test. It's not just about
This is for unit tests only, no DB access.
> I agree that reloading the environment can sometimes ve a bit slow. But
> you've got to do it if you want reliable tests.
I disagree. I think 10 seconds is completely un-acceptable to do proper
test-driven development. Since using this new system I write much
better unit tests because I have the freedom to run it over and over and
over after every small change.
Just like you don't have to start and stop your webserver when making
changes in development mode. Rails nicely has a setting to only cache
classes in production mode. So you make a change, and can refresh the
browser and see it right away. I want that same freedom in tests.
Because that's what makes me NOT want to write the test. Because I know
I can see the change right away in the browser.
Here's is the logic cleaned up and in a function:
def reload_and_run_unit_test(test_path, test)
load "test/unit/#{test_path}_test.rb"
reload!
klass = "#{test_path.split('/').last.titleize.gsub(/ /,
'')}Test".constantize
suite = Test::Unit::TestSuite.new(klass.to_s)
suite << klass.new(test)
runner = Test::Unit::UI::Console::TestRunner.new(suite)
runner.start
''
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---