我尝试安装RSpec时为什么会出现此错误?

时间:2017-01-05 05:24:29

标签: ruby-on-rails ruby rspec

之前我使用过RSpec,这是我第一次尝试运行时出现此错误:

rails generate rspec:install

导致此错误:

/Users/ldco2016/Projects/workout_app/config/application.rb:11:in `require': cannot load such file -- action_cable/engine (LoadError)
    from /Users/ldco2016/Projects/workout_app/config/application.rb:11:in `<top (required)>'
    from /Users/ldco2016/.rvm/gems/ruby-2.2.5/gems/spring-2.0.0/lib/spring/application.rb:82:in `require'
    from /Users/ldco2016/.rvm/gems/ruby-2.2.5/gems/spring-2.0.0/lib/spring/application.rb:82:in `preload'
    from /Users/ldco2016/.rvm/gems/ruby-2.2.5/gems/spring-2.0.0/lib/spring/application.rb:143:in `serve'
    from /Users/ldco2016/.rvm/gems/ruby-2.2.5/gems/spring-2.0.0/lib/spring/application.rb:131:in `block in run'
    from /Users/ldco2016/.rvm/gems/ruby-2.2.5/gems/spring-2.0.0/lib/spring/application.rb:125:in `loop'
    from /Users/ldco2016/.rvm/gems/ruby-2.2.5/gems/spring-2.0.0/lib/spring/application.rb:125:in `run'
    from /Users/ldco2016/.rvm/gems/ruby-2.2.5/gems/spring-2.0.0/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/ldco2016/.rvm/rubies/ruby-2.2.5/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/ldco2016/.rvm/rubies/ruby-2.2.5/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'

这是我的宝石文件:

来源'https://rubygems.org'

git_source(:github)do | repo_name |   repo_name =“#{repo_name} /#{repo_name}”除非repo_name.include?(“/”)   “https://github.com/# {repo_name}的.git” 端

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 4.2.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

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

group :development, :test do
  gem 'rspec-rails', '3.2.3'
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '~> 3.0.5'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  gem 'capybara', '2.4.4'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

这是我的config / application.rb:

require_relative 'boot'

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module WorkoutApp
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.
  end
end

2 个答案:

答案 0 :(得分:3)

此问题与RSpec无关。您正尝试在Rails 4应用程序中加载action_cable(根据您的Gemfile),这是 Rails 5 的内置功能。只需从您的application.rb。

中删除此行
require "action_cable/engine"

如果您不是真的需要独立加载Rails模块,只需将所有需求替换为:

require 'rails/all'

答案 1 :(得分:0)

app/application.rb中,评论"require "action_cable/engine"