Search code examples
ruby-on-railsrubyruby-on-rails-4rspecguard

Rails Guard say 'Rspec results failed' and one empty spec give dependency errors


I just updated my gems (Including rails to 4.1). I ran guard and everything worked fine. Then I created a new model and ran guard again. This time in the console everything looks good but the guard notification says Rspec results failed! I opened the spec of the newly created model (its empty) and just save it without changing. Then in the console i can see the following error :

    10:40:15 - INFO - Guard is now watching at '/home/pubudu/Projects/sumaga-asapuwa'
    10:43:55 - INFO - Running: spec/models/dcache_spec.rb
    /home/pubudu/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load': cannot load such file -- /home/pubudu/Projects/sumaga-asapuwa.bk/spec/models/dcache_spec.rb (LoadError)
        from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
        from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
        from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
        from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
        from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `each'
        from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load_spec_files'
        from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:22:in `run'
        from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
        from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'
        from /home/pubudu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/pubudu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from -e:1:in `<main>'
    [1] guard(main)> 

Any idea how to fix this?


Solution

  • Guard is watching the directory /home/pubudu/Projects/sumaga-asapuwa but it is trying to run a spec file in /home/pubudu/Projects/sumaga-asapuwa.bk/spec/models (i.e. with an extra .bk on the folder name.

    In the rspec section of your Guardfile you should have a line like:

    watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
    

    This is in the instruction to Guard that if a .rb file under the app directory changes, or is created, to run rspec on the corresponding spec file. This is defined to be relative to the directory Guard is watching.