 |
Forums |
Admin Discussion Forums: help Start New Thread
By: Tom Anderson
RE: Testing with Spawn [ reply ] 2008-03-11 03:11
|
Actually, I recommend using the :method=>:yield setting for testing. You can do this for all calls to spawn in the test enviornment by putting this in your environment.rb
Spawn::method :yield, 'test'
or just putting this in your test.rb
Spawn::method :yield
This will basically disable threading/forking and run the code inline so you don't have add waits to your tests.
|
By: Andy Duncan
Testing with Spawn [ reply ] 2008-03-06 19:51
|
This is probably obvious if you know what's going on, but it took me a little bit to figure out:
Rails test helper uses transactional fixtures, which means that any forked processes will see an empty table.
You have to do two things to test activerecord database hits when using spawn:
1: turn off transactional fixtures for that job:
-----------------
class SomeJobTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
# Replace this with your real tests.
-----------------
That will turn off transactions, but rails still puts the database back into a virgin(empty) state when the test completes, so:
2: You'll need to have the test wait until the forked process runs before exiting:
-----------------
Process.wait()
#some assertions about completeness
-----------------
Hope that helps
|
|
 |