Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with running Guard process: can't find singularize method

I followed the Rails Tutorial on setting up automated tests with Guard and Spork. Every once in a while, especially when saving an unedited template in my editor, Guard will complain (full backtrace):

ERROR: Problem with watch action!
undefined method `singularize' for "layouts":String

My Guardfile:

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

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{^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$})  do |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].singularize}_pages_spec.rb"] ### Look here ###
  end
  watch(%r{^app/views/(.+)/}) do |m|
    "spec/requests/#{m[1].singularize}_pages_spec.rb" ### Look here ###
  end
  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', :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 doesn't complain if I restart, but restarting is getting a bit annoying; admittedly, not as annoying as running rspec every time I want a test.

  • I tried the suggestion in this post, but I think .autotest may be the wrong file for guard, since this isn't fixing the issue.
  • The only similar error I found with Google doesn't seem related.
like image 368
jrhorn424 Avatar asked Mar 14 '12 22:03

jrhorn424


1 Answers

Actually, in the Rails tutorial they're adding require 'active_support/core_ext' at the top of the Guardfile.

I think this might fix your issue.

Also be sure to declare the spork guard before the rspec guard.

like image 150
rymai Avatar answered Oct 21 '22 18:10

rymai