\"Circular dependency detected\" error in ServerSpec

I've tripped over this error a few times; time to write it down.

A few times now, I've run serverspec-init, added a couple tests, then had the first Rake fail like so:

Circular dependency detected: TOP => default => spec => spec:all =>
spec:default => spec:all

Tasks: TOP => default => spec => spec:all => spec:default
(See full trace by running task with --trace)
Circular dependency detected:

Turns out that this is a known problem in Serverspec, but it's not exactly a bug. The problem appears to be that some part of the Vagrantfile I'm using is named "default". The original reporter said it was the hostname, but I'm not sure I have that in mine. In any case, this causes problems with the Rakefile: the target is default, but that also matches the hostname, and so it's circular and Baby Jesus cries.

(Side rant: I really wish the Serverspec project would use a proper bug tracker, rather than just having everything in pull requests. Grrr.)

One way around this is to change the Rakefile itself. Open it up and look for this part:

namespace :spec do
  targets = []
  Dir.glob('./spec/*').each do |dir|
next unless File.directory?(dir)
targets << File.basename(dir)
  end

  task :all     => targets
  task :default => :all

Comment out that last line, task :default => :all:

namespace :spec do
  targets = []
  Dir.glob('./spec/*').each do |dir|
next unless File.directory?(dir)
targets << File.basename(dir)
  end

  task :all     => targets
  # task :default => :all

Problem solved (though probably in a fairly hacky way...)