0

我正在学习 Hartl 的 Ruby on Rails 教程,并尝试使用无效信息测试用户注册,并且在运行 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'

这是我的规范/请求/user_pages_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

还有我的 Gemfile:

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

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

4

1 回答 1

0

您的错误说框架无法加载"/Users/kelvinyu/rails_projects/sample_app/signup with invalid information"显然不是文件的文件 - 文件是"spec/requests/user_pages_spec.rb". 尝试将所有内容都放在一行中 - 没有\ >(这个斜线尖括号仅意味着当 Michael Hartl 键入教程时可能存在换行符。

此外,请考虑互换使用描述和上下文。这将使您编写更清晰的规范。它没有魔法。RSpec 的源代码显示这context只是describe. 但是,当您同时使用两者编写规范时,含义会更加清晰。

于 2013-09-22T17:55:06.260 回答