How to combine autotest and spork in Rails testing?
Asked Answered
O

3

11

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

Overtop answered 25/11, 2010 at 7:9 Comment(0)
D
13

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.

Daudet answered 2/3, 2011 at 3:59 Comment(0)
P
4

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.rband 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.

Parkin answered 25/6, 2012 at 13:25 Comment(0)
S
0

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.

Syzygy answered 31/1, 2011 at 3:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.