簡體   English   中英

在“加載”中:無法加載此類文件(LoadError)

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

我正在關注ruby.railstutorial.org上的Rails教程,但現在很遺憾。 我在第3章中,它涉及rspec測試。 運行以下代碼后

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

我將以下命令傳遞到終端窗口

 bundle exec rspec spec/requests/static_pages_spec.rb

我收到以下輸出

/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'

規范與此代碼之前工作正常

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

這是我的寶石文件(感謝大家昨天對我的幫助)

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]

基本上,我不知道此輸出意味着什么。 我也不知道為什么rspec不對我的文件執行測試。 誰能幫我解決這個問題?

編輯:有沒有什么方法可以在這里編寫代碼而不會每行縮進4個空格? 那需要一段時間

聽起來您的工作目錄和Rails根目錄混在一起了。 RSpec規范應位於: RAILS_ROOT/spec/...

錯誤表明它無法加載: sample_app/app/views/spec/requests/static_pages_spec.rb

看來您的規格位於RAILS_ROOT/app/view/spec而非RAILS_ROOT/spec

運行rspec時,請確保您的工作目錄是rails根目錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM