简体   繁体   English

在“加载”中:无法加载此类文件(LoadError)

[英]in 'load': cannot load such file (LoadError)

I am following the Rails Tutorial from ruby.railstutorial.org but am unfortunately stumped right now. 我正在关注ruby.railstutorial.org上的Rails教程,但现在很遗憾。 I am in Chapter 3, which deals with rspec tests. 我在第3章中,它涉及rspec测试。 After running the following code 运行以下代码后

require 'spec_helper'

describe "Static pages" do
  describe "Home page" do
    it "should have the content 'Sample App'" do
      # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
      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 Sample App |Home')
    end

  describe "Help page" do
    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 Sample App |Help')
    end

  describe "About page" do
    it "should have the content 'About us'" do
      visit '/static_pages/about'
      expect(page).to have_content('About us')
    end
    it "should have the right title" do
      visit '/static_pages/about'
      expect(page).to have_title('Ruby on Rails Sample App |About')
  end
end

I passed in the following command to my terminal window 我将以下命令传递到终端窗口

 bundle exec rspec spec/requests/static_pages_spec.rb

I received the following output 我收到以下输出

/Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-   2.13.1/lib/rspec/core/configuration.rb:819:in `load': cannot load such file -- /Users/name/MyProjects/sample_app/app/views/spec/requests/static_pages_spec.rb (LoadError)
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

spec worked fine before with this code 规范与此代码之前工作正常

require 'spec_helper'

describe "Static pages" do

  describe "Home page" do

    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      expect(page).to have_content('Sample App')
    end
  end

  describe "Help page" do

    it "should have the content 'Help'" do
      visit '/static_pages/help'
      expect(page).to have_content('Help')
    end
  end

  describe "About page" do

    it "should have the content 'About Us'" do
      visit '/static_pages/about'
      expect(page).to have_content('About Us')
    end
  end
end

Here is my gemfile (thanks guys for helping me yesterday) 这是我的宝石文件(感谢大家昨天对我的帮助)

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.4'

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
end


# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more:     https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

Basically, I have no idea what this output means. 基本上,我不知道此输出意味着什么。 I also have no idea why rspec doesn't perform tests on my files. 我也不知道为什么rspec不对我的文件执行测试。 Can anyone help me solve this? 谁能帮我解决这个问题?

Edit: Is there any way to write code on here without indenting 4 spaces of every line? 编辑:有没有什么方法可以在这里编写代码而不会每行缩进4个空格? That takes quite a while 那需要一段时间

It sounds like your working directory and your Rails root are mixed up. 听起来您的工作目录和Rails根目录混在一起了。 RSpec specs should be in: RAILS_ROOT/spec/... RSpec规范应位于: RAILS_ROOT/spec/...

The error is stating it is unable to load: sample_app/app/views/spec/requests/static_pages_spec.rb 错误表明它无法加载: sample_app/app/views/spec/requests/static_pages_spec.rb

That looks like your spec is in RAILS_ROOT/app/view/spec not RAILS_ROOT/spec . 看来您的规格位于RAILS_ROOT/app/view/spec而非RAILS_ROOT/spec

Make sure your working directory is the rails root when you run rspec . 运行rspec时,请确保您的工作目录是rails根目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM