2012-03-14 39 views
20

Tôi đã theo dõi Rails Tutorial khi thiết lập thử nghiệm tự động với Guard and Spork. Mỗi một lần trong một thời gian, đặc biệt là khi tiết kiệm một mẫu chưa được chỉnh sửa trong trình soạn thảo của tôi, Guard sẽ phàn nàn (full backtrace):Lỗi khi chạy quy trình Bảo vệ: không thể tìm thấy phương thức số ít

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 không phàn nàn nếu tôi khởi động lại , nhưng việc khởi động lại hơi khó chịu; thừa nhận, không phải là gây phiền nhiễu khi chạy rspec mỗi lần tôi muốn thử nghiệm.

  • Tôi đã thử các gợi ý trong this post, nhưng tôi nghĩ .autotest có thể là tập tin sai cho bảo vệ, vì đây không phải là khắc phục vấn đề.
  • only similar error Tôi thấy có vẻ như Google không liên quan.

Trả lời

32

Trên thực tế, in the Rails tutorial chúng đang thêm require 'active_support/core_ext' ở đầu tệp Guardfile.

Tôi nghĩ điều này có thể khắc phục được sự cố của bạn.

Ngoài ra, hãy đảm bảo khai báo bảo vệ của bộ bảo vệ trước khi bảo vệ rspec.

+7

Đúng, '# singularize' là từ [ActiveSupport :: Inflector] (http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html), vì vậy' require 'active_support/inflector'' là đủ. – Netzpirat

+2

Doh! Nếu đó là một ví dụ mã đầy đủ, tôi đã sao chép và dán. : D Hy vọng rằng điều này sẽ giúp linh hồn không may mắn có vấn đề này trong tương lai. Ngoài ra, cảm ơn cho tip về bảo vệ spork đầu tiên! – jrhorn424

+0

Giúp tôi ít nhất :) Thanx! –

Các vấn đề liên quan