Ruby on rails Ruby中的Rspec加载错误

Ruby on rails Ruby中的Rspec加载错误,ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,我正在学习Hartl的RubyonRails教程,试图测试用户注册时是否有无效信息,运行rspec时出现“加载错误”。我不确定如何修复这个错误,因为我已经更新了我的gem文件 $ bundle exec rspec spec/requests/user_pages_spec.rb \ > -e "signup with invalid information" 然后我得到这个信息: /Users/kelvinyu/.rvm/gems/ruby-2.0.0-p247@railstutori

我正在学习Hartl的RubyonRails教程,试图测试用户注册时是否有无效信息,运行rspec时出现“加载错误”。我不确定如何修复这个错误,因为我已经更新了我的gem文件

$ bundle exec rspec spec/requests/user_pages_spec.rb \ > -e "signup with invalid information"
然后我得到这个信息:

/Users/kelvinyu/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load': cannot load such file -- /Users/kelvinyu/rails_projects/sample_app/signup with invalid information (LoadError)
from /Users/kelvinyu/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /Users/kelvinyu/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Users/kelvinyu/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Users/kelvinyu/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/kelvinyu/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:77:in `rescue in run'
from /Users/kelvinyu/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:73:in `run'
from /Users/kelvinyu/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
以下是我的规范/请求/用户页面\u spec.rb:

require 'spec_helper'

describe "UserPages" do

  subject { page }

  describe "profile page" do
    let(:user) { FactoryGirl.create(:user) }
    before { visit user_path(user) }

    it { should have_content(user.name) }
    it { should have_title(user.name) }
  end

  describe "signup page" do
    before { visit signup_path }
      # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
    it { should have_content('Sign up') }
    it { should have_title(full_title('Sign up')) }
  end

  describe "signup" do

    before { visit signup_path }

    let(:submit) { "Create my account" }

    describe "with invalid information" do
      it "should not create a user" do
        expect { click_button submit }.not_to change(User, :count)
      end
    end

    describe "with valid information" do
      before do
        fill_in "Name",         with: "Example User"
        fill_in "Email",        with: "user@example.com"
        fill_in "Password",     with: "foobar"
        fill_in "Confirmation", with: "foobar"
      end

      it "should create a user" do
        expect { click_button submit }.to change(User, :count).by(1)
      end
    end
  end
end
和我的档案:

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.0'
gem 'bootstrap-sass', '2.3.2.0'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.1.2'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.9'

group :development, :test do
  gem 'sqlite3', '1.3.7'
  gem 'rspec-rails', '2.13.1'
  # The following optional lines are part of the advanced setup.
  gem 'guard-rspec', '2.5.0'
  gem 'spork-rails', github: 'sporkrb/spork-rails'
  gem 'guard-spork', '1.5.0'
  gem 'childprocess', '0.3.6'
end

group :test do
  gem 'selenium-webdriver', '2.0.0'
  gem 'capybara', '2.1.0'
  gem 'factory_girl_rails', '4.2.1'
  gem 'cucumber-rails', '1.3.0', :require => false
  gem 'database_cleaner', github: 'bmabey/database_cleaner'

  # Uncomment this line on OS X.
  # gem 'growl', '1.0.3'

  # Uncomment these lines on Linux.
  # gem 'libnotify', '0.8.0'

  # Uncomment these lines on Windows.
  # gem 'rb-notifu', '0.0.4'
  # gem 'win32console', '1.3.2'
end

gem 'sass-rails', '4.0.0'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.0'
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end
我是否遗漏了其他信息?修复此错误的适当步骤是什么

编辑:

此处的等级库帮助器:

require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the StaticPagesHelper. For example:
# describe StaticPagesHelper do
#   describe "string concat" do
#     it "concats two strings with spaces" do
#       helper.concat_strings("this","that").should == "this that"
#     end
#   end
# end
#describe StaticPagesHelper do
#   pending "add some examples to (or delete) #{__FILE__}"
#end

我注意到它是空的,但是教程的步骤不需要任何更改。

您的错误表明框架无法加载文件
“/Users/kelvinyu/rails\u projects/sample\u app/signup with invalid information”
,该文件显然不是
“spec/requests/user\u pages\u spec.rb”
。尝试将所有内容都放在一行中,而不使用
\>
(此斜线角括号仅表示在Michael Hartl键入教程时,可能有一个换行符


另外,要注意互换使用。这会使您编写更清晰的规范。这并没有什么神奇之处。RSpec的源代码显示,
context
只是
descripe
的另一个名称。但是当您编写同时使用这两种规范的规范时,含义会更清晰。

尝试在不使用“\”的情况下运行RSpec,即只需键入$bundle exec RSpec spec/requests/user_pages_spec.rb>-e“使用无效信息注册”你说你在共享你的
spec\u helper
文件,但那不是你共享的。你能共享你的
spec\u helper
文件吗?@SachinSingh-我尝试按照你的建议运行rspec,但同样的错误消息显示。@PeterAlfvin我已经添加了spec helper,但它是空的。你认为这是错误的根源吗?什么你想在rspec命令行中处理
\>
吗?谢谢你的解释。这个解决方案奏效了,似乎
\>
是一个换行符。正确的命令应该是
bundle exec rspec spec/requests/user\u pages\u spec.rb\
,我想你仍然误解了这个情况。the“-e”指定要运行的测试。如果完全忽略参数,则运行的是整个文件。另外,您是否介意指向教程中包含
\>
的任何内容?@PeterAlfvin!当然!就在图7.17的后面。因此,在我运行rspec之后,如上所述,作为
bundle exec rspec spec/requests/user\u pages\u spec.rb\
显示,我可以通过键入
-e“使用无效信息注册”
@PeterAlfvin来运行测试的其余部分,这就是我看到
\>
正在使用的地方,但实际上我将该部分误读为一个命令行。