Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Guard/Spork talk

The Problem

$ time rails runner "puts 1"

real    0m14.917s
user    0m10.923s
sys 0m3.007s[/code]
$ time rspec ./spec/models/asset_spec.rb

Finished in 0.02351 seconds

real    0m19.014s
user    0m13.108s
sys 0m3.440s

... so you wait 14seconds for Rails to boot, to run a 0.02 seconds spec. Now try to do it every few minutes.

The Solution

Guard: Guard is a command line tool to easily handle events on files modifications (FSEvent / Inotify / Polling support).

Guard-Spork: - reloads Spork on code changes that are cached (like lib/, initializers, etc) Guard-RSpec: - runs specs on code changes (re runs until green, Growl alerts)

More guards:

$ guard

So now the 19 seconds are cut down to: ...

$ time rspec ./spec/models/asset_spec.rb

Finished in 0.01704 seconds

real    0m3.046s
user    0m0.400s
sys 0m0.116s

Why 3 seconds? Because there are still some things we reload on every run of specs (although this can be probably optimized).

Besides this, you also save time by not having to run specs manually. So guard-rspec is relevant even if you don't have a big Rails project or non Rails project at all.

More info

Spork reloading has its issues (that's the main reason we use Guard along with it). Some useful links that will help you out: - My Rails 3 template incorporates many of the tips above and some more. Although a bit outdates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.