Ruby on rails 4 运行$rspec spec时未初始化常量ApplicationController(NameError)

Ruby on rails 4 运行$rspec spec时未初始化常量ApplicationController(NameError),ruby-on-rails-4,rspec-rails,spree,Ruby On Rails 4,Rspec Rails,Spree,我试图在Rails4.1中使用rspec进行tdd。我正在rails中使用spree commerce和cms gem。但当我运行$rspec spec时,它会给我以下错误 uninitialized constant ApplicationController (NameError) from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require' from /home/za

我试图在Rails4.1中使用rspec进行tdd。我正在rails中使用spree commerce和cms gem。但当我运行$rspec spec时,它会给我以下错误

uninitialized constant ApplicationController (NameError)
from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/bundler/gems/spree-refinery-authentication-f9168bd7fe97/lib/spree_refinery_authentication/engine.rb:1:in `<top (required)>'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/bundler/gems/spree-refinery-authentication-f9168bd7fe97/lib/spree-refinerycms-authentication.rb:1:in `<top (required)>'
from /home/zapbuild/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `require'
from /home/zapbuild/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/zapbuild/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `each'
from /home/zapbuild/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `block in require'
from /home/zapbuild/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `each'
from /home/zapbuild/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `require'
from /home/zapbuild/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler.rb:132:in `require'
from /var/www/ws_groupbuy/config/application.rb:7:in `<top (required)>'
from /var/www/ws_groupbuy/config/environment.rb:2:in `require'
from /var/www/ws_groupbuy/config/environment.rb:2:in `<top (required)>'
from /var/www/ws_groupbuy/spec/spec_helper.rb:3:in `require'
from /var/www/ws_groupbuy/spec/spec_helper.rb:3:in `<top (required)>'
from /var/www/ws_groupbuy/spec/models/spree/product_spec.rb:1:in `require'
from /var/www/ws_groupbuy/spec/models/spree/product_spec.rb:1:in `<top (required)>'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in `load'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in `block in load_spec_files'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in `each'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in `load_spec_files'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.99.1/lib/rspec/core/command_line.rb:18:in `run'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.99.1/lib/rspec/core/runner.rb:103:in `run'
from /home/zapbuild/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.99.1/lib/rspec/core/runner.rb:17:in `block in autorun'

从错误中看,您的宝石似乎丢失了。打开/home/zapbuild/.rvm/gems/ruby-2.1.2/gems/polyglot-0.3.5/lib/polyglot.rb,查看第65行中的内容,然后从那里开始查看缺少哪些gems,并将其放在gem文件中。使用正确的版本重新安装gem
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require "capybara/rspec"
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.infer_spec_type_from_file_location!