简体   繁体   中英

in 'load': cannot load such file (LoadError)

I am following the Rails Tutorial from ruby.railstutorial.org but am unfortunately stumped right now. I am in Chapter 3, which deals with rspec tests. 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. Can anyone help me solve this?

Edit: Is there any way to write code on here without indenting 4 spaces of every line? That takes quite a while

It sounds like your working directory and your Rails root are mixed up. RSpec specs should be in: RAILS_ROOT/spec/...

The error is stating it is unable to load: 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 .

Make sure your working directory is the rails root when you run rspec .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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