Could not load 'guard/spork' or find class Guard::Spork

2,450 views
Skip to first unread message

Shauna

unread,
May 11, 2012, 7:56:39 PM5/11/12
to guar...@googlegroups.com
I've been working my way through Michael Hartl's tutorial : http://ruby.railstutorial.org/chapters/static-pages?version=3.2#sec:spork.

I'm on a Windows 7 system, so I know I can't use guard-spork. But I could swear that before I was able to start a Ruby DRb server and then run 'guard' without any problems. Now I can start up a Ruby DRb server fine and it does process my RSpec tests. But when I then try to 'bundle exec guard' I get:
   ERROR: Could not load 'guard/spork' or find class Guard::Spork ...
   ERROR: Invalid Guardfile, original error is:
   undefined method 'new' for nil:NilClass
   ERROR: No guards found in Guardfile, please add at least one. ...
   Guard is now watching at 'C:/Sites/rm403'
and it doesn't detect when I change a spec file.
Here is the 'C:/Sites/rm403/Guardfile:

guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch(%r{^config/environments/.+\.rb$})
  watch(%r{^config/initializers/.+\.rb$})
  watch('Gemfile')
  watch('Gemfile.lock')
  watch('spec/spec_helper.rb') { :rspec }
  watch('test/test_helper.rb') { :test_unit }
  watch(%r{features/support/}) { :cucumber }
  watch('spec/support/')
end

guard 'rspec', :version => 2, :all_after_pass => false, :cli => '--drb --color' do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$})                 { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m|
        ["spec/routing/#{m[1]}_routing_spec.rb",
         "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
         "spec/acceptance/#{m[1]}_spec.rb",
         "spec/requests/#{m[1]}_spec.rb"] }
#       (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
#                           "spec/requests/#{m[1].singularize}_pages_spec.rb")]
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }
  # Capybara request specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }
end

So is there some syntax error in my Guardfile that's preventing guard from interpreting it correctly? I tried remming out the whole spork section but then spork doesn't work at all. Can someone point me in the right direction? Thanks.

Thibaud Guillaume-Gentil

unread,
May 15, 2012, 3:54:28 AM5/15/12
to guar...@googlegroups.com
Can you give your Gemfile? It seems that guard-spork is missing.

Shauna Haines

unread,
Sep 9, 2012, 1:50:19 PM9/9/12
to rails2012, guar...@googlegroups.com
Maybe my original post wasn't explicit enough: the guard-spork gem
won't load on Windows 7, so it is not in my Gemfile.

But I remember being able to start them separately before - first
spork and then guard.

Sunday, September 9, 2012, 8:54:08 AM, rails2012 wrote:

r> It's funny. I missed the same thing:

r> gem 'guard-spork', '0.3.2'

rails2012

unread,
Sep 9, 2012, 4:40:44 PM9/9/12
to guar...@googlegroups.com, rails2012
I am using windows 7 home premium.  I successfully followed through chapter 3.

Shauna Haines

unread,
Sep 9, 2012, 4:55:34 PM9/9/12
to rails2012, guar...@googlegroups.com
I see the tutorial has been updated again to use gem 'rails', '3.2.8',
and that the guard and spork related gems also have slightly different
version numbers than when I first tried it back in May. Maybe that
fixes it.

Sunday, September 9, 2012, 1:40:44 PM, rails2012 wrote:

r> I am using windows 7 home premium. I successfully followed through chapter
r> 3.

Shauna Haines

unread,
Sep 9, 2012, 7:59:57 PM9/9/12
to rails2012, guar...@googlegroups.com
Nope, it still doesn't work for me!

I'm up to the end of Chapter 8 now but I went to the end of Chapter 3
and updated my Gemfile and Guardfile with respect to guard and spork.
So in my Gemfile under both :development and :test I tried:
gem 'rspec-rails', '2.11.0'
gem 'guard-rspec', '0.5.5'
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'

'bundle install' works but 'bundle exec guard' gets:
ERROR: <-[0mCould not load 'guard/spork-rails' or find class
Guard::SporkRails... but then it started "watching" anyway, followed
by a [Listen warning]: Missing dependency 'wdm' (version '~> 0.0.3')!
Please add [it] to your Gemfile...

My old Gemfile had the line gem 'spork-rails' commented out (and it
doesn't appear in the tutorial's Gemfile either), but I uncommented it
and then 'bundle install' got: Bundler could not find compatible
versions for gem "spork": In Gemfile: spork-rails ()=0 x86-mingw32
depends on spork ()=1.0rc0 x86-mingw32

By the way, I am deleting the Gemfile.lock file each time I rerun
'bundle install'.

So I tried changing gem 'spork', '0.9.0' to just gem 'spork'. Now
'bundle install' works, but 'bundle exec guard' gets the same "Could
not load 'guard/spork-rails'..." error message, watching, and 'wdm'
warning as before.

I changed a line in one of my /spec/requests files, but there was no
response from guard.

Can you check your Gemfile for me and list the versions you have of
all the guard- and spork- related gems? Is 'spork-rails' in there?

Thanks!

By the way, I am on a 64-bit machine.

Sunday, September 9, 2012, 1:55:34 PM, Shauna Haines wrote:

SH> I see the tutorial has been updated again to use gem 'rails', '3.2.8',
SH> and that the guard and spork related gems also have slightly different
SH> version numbers than when I first tried it back in May. Maybe that
SH> fixes it.

rails2012

unread,
Sep 9, 2012, 11:36:25 PM9/9/12
to guar...@googlegroups.com, rails2012
Here is my whole Gemfile:


gem 'rails', '3.2.8'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development do
  gem 'sqlite3'
  gem 'rspec-rails', '2.11.0'
  gem 'guard-rspec', '0.5.5'
  gem 'guard-spork', '0.3.2'
  gem 'spork', '0.9.0'
  gem 'wdm', '~> 0.0.3'
end


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.2.3'
end

gem 'jquery-rails'

group :test do
  gem 'capybara', '1.1.2'
  gem 'rb-fchange', '0.0.5'
  gem 'rb-notifu', '0.0.4'
  gem 'win32console', '1.3.0'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

group :production do 
  # gems specifically for Heroku go here 
  gem "pg" 
end 


#gem 'whenever', :require => false
gem 'rufus-scheduler', :require => false

Thibaud Guillaume-Gentil

unread,
Sep 10, 2012, 2:49:48 AM9/10/12
to guar...@googlegroups.com
Please try with guard-spork 1.2.0 it should work on Windows now.

On Sep 9, 2012, at 17:54 , rails2012 <dere...@hotmail.com> wrote:

> It's funny. I missed the same thing:
>
> gem 'guard-spork', '0.3.2'
>
>
>
> On Tuesday, May 15, 2012 12:54:28 AM UTC-7, thibaudgg wrote:

Shauna Haines

unread,
Sep 10, 2012, 2:52:54 PM9/10/12
to rails2012, guar...@googlegroups.com
I changed my Gemfile similar to yours (listed below), restarted my
computer, deleted the Gemfile.lock file, ran 'bundle install' (no
problems with that), and ran 'bundle exec guard'. I got the same
messages as before:
ERROR: <-[0mCould not load 'guard/spork-rails' or find class
Guard::SporkRails
ERROR: <-[0mcannot load such file -- guard/spork-rails
ERROR: <-[0mInvalid Guardfile, original error is:
undefined method 'new' for nil:NilClass
ERROR: <-[0mNo guards found in Guardfile, please add at least one.
...
<-[0mGuard is now watching at...

Then I changed a spec file, and there was no response from guard.
Then I started 'bundle exec spork' in another "Command Prompt with
Ruby and Rails" window, and changed the spec file again. There was
still no response.

My Gemfile:
source 'https://rubygems.org'

gem 'rails', '3.2.8'
gem 'bootstrap-sass', '2.0.0'
gem 'bcrypt-ruby', '3.0.1' # Chap 6
gem 'pg', '0.13.1'

group :development do
# gem 'mongrel', '1.2.0.pre2' # for ruby 1.9.2
gem 'rspec-rails', '2.11.0' # '2.9.0', '2.10.0'
gem 'guard-rspec', '0.5.5'
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'
gem 'wdm', '~> 0.0.3'

gem 'annotate', '~> 2.4.1.beta'
end

group :test do
# gem 'rspec-rails', '2.11.0' # '2.9.0', '2.10.0'
# gem 'guard-rspec', '0.5.5'
# gem 'guard-spork', '0.3.2'
# gem 'spork', '0.9.0'
# gem 'wdm', '~> 0.0.3'

gem 'capybara', '1.1.2'
gem 'rb-fchange', '0.0.5'
gem 'rb-notifu', '0.0.4'
gem 'win32console', '1.3.0'
gem 'win32-process'
# gem 'guard-spork' # guard-spork does not work in Windows! - try again w/ later versions
# gem 'spork', '> 0.9.0.rc9'
# gem 'spork-rails'
# gem 'guard-rspec'
gem 'factory_girl_rails', '1.4.0'
gem 'cucumber-rails', '1.2.1', require: false
gem 'database_cleaner', '0.7.0'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5' # '~> 3.2.3', '3.2.4'
gem 'coffee-rails', '3.2.2' # '~> 3.2.2'
gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.0' # '~> 2.0.0'

#group :production do
# gem 'pg', '0.13.1'
#end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

My Guardfile:
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'spork-rails', :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb')
watch('test/test_helper.rb')
end

# guard 'rspec', :version => 2 do
guard 'rspec', :version => 2, :all_after_pass => false, :cli => '--drb' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m|
["spec/routing/#{m[1]}_routing_spec.rb",
"spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
"spec/acceptance/#{m[1]}_spec.rb",
"spec/requests/#{m[1]}_spec.rb",
(m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
"spec/requests/#{m[1].singularize}_pages_spec.rb")] }

watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
# watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
watch(%r{^app/views/(.+)/}) do |m|
(m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
"spec/requests/#{m[1].singularize}_pages_spec.rb")
end
end

guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end


guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb')
watch('test/test_helper.rb')
end


Sunday, September 9, 2012, 8:36:25 PM, rails2012 wrote:

r> Here is my whole Gemfile:

r> source 'https://rubygems.org'

r> gem 'rails', '3.2.8'

r> # Bundle edge Rails instead:
r> # gem 'rails', :git => 'git://github.com/rails/rails.git'
r> group :development do
r> gem 'sqlite3'
r> gem 'rspec-rails', '2.11.0'
r> gem 'guard-rspec', '0.5.5'
r> gem 'guard-spork', '0.3.2'
r> gem 'spork', '0.9.0'
r> gem 'wdm', '~> 0.0.3'
r> end


r> # Gems used only for assets and not required
r> # in production environments by default.
r> group :assets do
r> gem 'sass-rails', '~> 3.2.3'
r> gem 'coffee-rails', '~> 3.2.1'

r> # See https://github.com/sstephenson/execjs#readme for more supported
r> runtimes
r> # gem 'therubyracer', :platforms => :ruby

r> gem 'uglifier', '>= 1.2.3'
r> end

r> gem 'jquery-rails'

r> group :test do
r> gem 'capybara', '1.1.2'
r> gem 'rb-fchange', '0.0.5'
r> gem 'rb-notifu', '0.0.4'
r> gem 'win32console', '1.3.0'
r> end

r> # To use ActiveModel has_secure_password
r> # gem 'bcrypt-ruby', '~> 3.0.0'

r> # To use Jbuilder templates for JSON
r> # gem 'jbuilder'

r> # Use unicorn as the app server
r> # gem 'unicorn'

r> # Deploy with Capistrano
r> # gem 'capistrano'

r> # To use debugger
r> # gem 'debugger'

r> group :production do
r> # gems specifically for Heroku go here
r> gem "pg"
r> end


r> #gem 'whenever', :require => false
r> gem 'rufus-scheduler', :require => false


Shauna Haines

unread,
Sep 10, 2012, 3:06:41 PM9/10/12
to Thibaud Guillaume-Gentil, guar...@googlegroups.com
Sorry, Thibaud, I missed your email earlier. But I just now tried
changing my version to guard-spork 1.2.0 and that made no difference
in my results.

Sunday, September 9, 2012, 11:49:48 PM, Thibaud Guillaume-Gentil wrote:

TGG> Please try with guard-spork 1.2.0 it should work on Windows now.

rymai

unread,
Sep 10, 2012, 5:05:23 PM9/10/12
to guar...@googlegroups.com, Thibaud Guillaume-Gentil
Hi,

First thing, guard-spork-rails doesn't exist : http://rubygems.org/gems/guard-spork-rails so you should remove it from your Guardfile (that's the cause of the "Could not load 'guard/spork-rails' or find class Guard::SporkRails" issue you're having);
Secondly, in your Guardfile you should move the "guard 'spork'" block before the "guard 'rspec'" block.

I hope that helps,
Regards.

Rémy

Shauna Haines

unread,
Sep 11, 2012, 1:17:25 AM9/11/12
to rymai, guar...@googlegroups.com, Thibaud Guillaume-Gentil
Yes, Rᅵmy, thank you, thank you! Moving the "guard 'spork'" block
from before to after the "guard 'rspec'" block did the trick!

By the way, I don't have a gem called 'guard-spork-rails' in my
Gemfile. It's a mystery to me where the wording of that "Could not
load 'guard/spork-rails' or find class Guard::SporkRails" message was
coming from. But moving the guard 'spork' block to the bottom of the
Guardfile made it go away, as well as activating guard to watch for my
rspec tests.

Shauna

Monday, September 10, 2012, 2:05:23 PM, rymai wrote:

r> Hi,

r> First thing, guard-spork-rails doesn't exist
r> : http://rubygems.org/gems/guard-spork-rails so you should remove it from
r> your Guardfile (that's the cause of the "Could not load 'guard/spork-rails'
r> or find class Guard::SporkRails" issue you're having);
r> Secondly, in your Guardfile you should move the "guard 'spork'" block
r> before the "guard 'rspec'" block.

r> I hope that helps,
r> Regards.

r> Rᅵmy

r> On Monday, September 10, 2012 9:07:18 PM UTC+2, Shauna wrote:
>>
>> Sorry, Thibaud, I missed your email earlier. But I just now tried
>> changing my version to guard-spork 1.2.0 and that made no difference
>> in my results.
>>
>> Sunday, September 9, 2012, 11:49:48 PM, Thibaud Guillaume-Gentil wrote:
>>
>> TGG> Please try with guard-spork 1.2.0 it should work on Windows now.
>>
>> TGG> On Sep 9, 2012, at 17:54 , rails2012
>> <dere...@hotmail.com<javascript:>>

Rémy Coutable

unread,
Sep 11, 2012, 3:31:19 AM9/11/12
to Shauna Haines, guar...@googlegroups.com, Thibaud Guillaume-Gentil
You're welcome Shauna!! Just a quick note, you have to put the "guard 'spork'" *at the top* of your Guardfile (at least before the "guard 'rspec'" block), not at the bottom (as you said in your previous reply).

Regarding "guard-spork-rails", that's the point actually, since you had "guard 'spork-rails', :rspec_env => { 'RAILS_ENV' => 'test' } do" in your Guardfile, Guard tried to search for a guard/spork-rails file or a Guard::SporkRails class but since it wasn't in your Gemfile (obviously since the gem doesn't exist at all!) an error was thrown.

I hope that clarifies a bit how Guard works, I encourage you to read its source code, it's not that complex! ;)

Regards,
Rémy

On Sep 11, 2012, at 07:17 , Shauna Haines <slha...@gmail.com> wrote:

> Yes, Rémy, thank you, thank you! Moving the "guard 'spork'" block
> from before to after the "guard 'rspec'" block did the trick!
>
> By the way, I don't have a gem called 'guard-spork-rails' in my
> Gemfile. It's a mystery to me where the wording of that "Could not
> load 'guard/spork-rails' or find class Guard::SporkRails" message was
> coming from. But moving the guard 'spork' block to the bottom of the
> Guardfile made it go away, as well as activating guard to watch for my
> rspec tests.
>
> Shauna
>
> Monday, September 10, 2012, 2:05:23 PM, rymai wrote:
>
> r> Hi,
>
> r> First thing, guard-spork-rails doesn't exist
> r> : http://rubygems.org/gems/guard-spork-rails so you should remove it from
> r> your Guardfile (that's the cause of the "Could not load 'guard/spork-rails'
> r> or find class Guard::SporkRails" issue you're having);
> r> Secondly, in your Guardfile you should move the "guard 'spork'" block
> r> before the "guard 'rspec'" block.
>
> r> I hope that helps,
> r> Regards.
>
> r> Rémy
Reply all
Reply to author
Forward
0 new messages