The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource. (Errno::ENOSPC)

Problem

When using the guard gem together with spork and cucumber and rspec to automate testing in your rails app, you get the following error:

The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource. (Errno::ENOSPC)

which also causes the guard to stop running.

Solution

Looking at the directory where the error takes place it appears there are a lot of temp files in the public/uploads/tmp directory that are not cleared up (using carrierwave for image uploading).
Maybe adding an initializer as suggested here would solve the clearing up of the files.
Otherwise by manually deleting the files and running guard again, it should work as expected.