Ruby on rails Can';t执行$time rspec spec/requests/static\u pages\u spec.rb

Ruby on rails Can';t执行$time rspec spec/requests/static\u pages\u spec.rb,ruby-on-rails,ruby-on-rails-4,rspec,Ruby On Rails,Ruby On Rails 4,Rspec,我正在以MichaelHartl的RubyonRails教程为例,但我被卡住了 每次尝试运行以下测试时,我都会出错: time rspec spec/requests/static_pages_spec.rb 我的错误: Gemfile:## 操作系统:Ubuntu 14.04 我一直在寻找解决办法,但没有找到。请记住,我是RubyonRails和web开发的新手。您的错误是: cannot load such file -- /home/i/rails_projects/sample_ap

我正在以MichaelHartl的RubyonRails教程为例,但我被卡住了

每次尝试运行以下测试时,我都会出错:

time rspec spec/requests/static_pages_spec.rb 
我的错误:

Gemfile:## 操作系统:Ubuntu 14.04

我一直在寻找解决办法,但没有找到。请记住,我是RubyonRails和web开发的新手。

您的错误是:

cannot load such file -- /home/i/rails_projects/sample_app/spec/spec/requests/static_pages_spec.rb (LoadError)
这意味着RSpec找不到规范。我看到您在文件路径中有两次
spec
。/sample\u app/spec/spec/。

您应该将规格保存在Rails应用程序的
spec
目录下。因此,路径应该是:
/sample\u app/spec/
,如下所示。修复该问题,然后重试。它应该会起作用

更新 因此,在本地运行代码后,我发现了问题。gem
guard spork
存在gem依赖性问题

你只需要升级这个宝石。在您的
文件中

gem'guard spork',1.5.0'
更改为
gem'guard spork',2.1.0'

然后,
bundle安装

然后运行
time rspec


一切都会顺利进行:-)

请出示
spec\u helper.rb
这是它是的,总是从那里我试图解决这个问题,并且又得到了一个。现在,如果我运行这个命令,我会得到:~/rails\u projects/sample\u app$time rspec spec/requests/static\u pages\u spec.rb/home/I/.rvm/gems/ruby-2.0.0-p643@railstutorial_rails_4_0/gems/guard-spork-1.5.0/lib/guard/spork.rb:2:in'require':无法加载这样的文件--guard/guard(LoadError)下面答案中的解决方案。将gem'guard spork'-从'1.5.0'更新为'2.1.0':Gemfile和Gemfile.lock注释不用于扩展讨论;这段对话已经结束。
require 'spec_helper'
 
describe "StaticPages" do
 
  describe "Home page" do
    it "It should have the content 'Sample App'" do
      visit '/static_pages/home'
      expect(page).to have_content('Sample App')
    end
    it "should have the right title" do
          visit '/static_pages/home'
          expect(page).to have_title("Ruby on Rails Tutorial Sample App | Home")
        end
  end
 
describe "Help page" do
    it "It should have the content 'Help'" do
      visit '/static_pages/help'
      expect(page).to have_content('Help')
    end
    it "should have the right title" do
          visit '/static_pages/help'
          expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help")
        end
  end
 
describe "About page" do
    it "It should have the content 'About Us'" do
      visit '/static_pages/about'
      expect(page).to have_content('About Us')
    end
  end
    it "should have the right title" do
          visit '/static_pages/about'
          expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us")
        end
describe "Contact" do
    it "It should have the content 'Contact'" do
      visit '/static_pages/contact'
      expect(page).to have_content('Contact')
    end
  end
    it "should have the right title" do
          visit '/static_pages/contact'
          expect(page).to have_title("Ruby on Rails Tutorial Sample App | Contact")
        end
 
end
cannot load such file -- /home/i/rails_projects/sample_app/spec/spec/requests/static_pages_spec.rb (LoadError)