问题
Autotest increases the speed at which tests run by running only the changed tests.
But I want to push it even further by using spork to preload the Rails environment, so that I will get even faster feedback.
Is this possible?
Autotest : https://github.com/grosser/autotest
Spork : http://github.com/timcharper/spork
回答1:
ARTICLE1 mikbe has you covered! I would attempt to rephrase it here, but the post does such a great job.
If you happen to be on OSX, there are also instructions to utilize Growl for tray notifications.
ARTICLE2 Ruby Inside also has a walkthrough for Rails 3 and RSpec 2.
回答2:
If you use Ruby 1.9 and want to use spork and autotest together with Test::Unit (actually MiniTest) try this:
Gemfile:
group :test do
# Newer version of test::unit:
gem 'minitest'
# spork preloads a rails instance which is forked every time the tests are
# run, removing test startup time.
gem 'spork'
# Run 'spork minitest' to start drb server (test server). Use 'testdrb' to
# run individual tests via spork.
gem 'spork-minitest'
# Run 'bundle exec autotest' to rerun relevant tests whenever a file/test is
# changed. '.autotest' makes sure the tests are run via test server (spork).
gem 'autotest-standalone'
# -pure gives us autotest without ZenTest gem.
gem 'autotest-rails-pure'
end
.autotest:
class Autotest
# run tests over drb server (spork)
def make_test_cmd files_to_test
if files_to_test.empty?
"" # no tests to run
else
"testdrb #{files_to_test.keys.join(' ')}"
end
end
end
(Note: Instructions says bin/testdrb
, but I changed it to testdrb
to make it work for me.)
In a terminal:
spork minitest --bootstrap
Edit test/test_helper.rb
and follow instructions.
After the above setup is done once, you can start the test server:
spork minitest
Finally start autotest in another terminal:
bundle exec autotest
And (hopefully) enjoy really fast autotesting with MiniTest.
回答3:
I haven't tried it yet, but there's a section in chapter 3 of the RailsTutorial that tells some "hacks" to set up spork. The tutorial currently says:
... as of this writing Spork doesn’t officially support Rails 3
The chapter goes on to tell how to set it up with autotest. One thing to know is that you'll need
--drb
in your .rspec file.
来源:https://stackoverflow.com/questions/4274499/how-to-combine-autotest-and-spork-in-rails-testing