ruby-on-rails – Rspec请求规格中的Rails 4中的循环依赖错误

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rspec请求规格中的Rails 4中的循环依赖错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个运行在Rails 4 / Ruby 2上的应用程序.前端正在使用Ember开发.

当运行rake规范时,我得到以下异常.它似乎只发生在Rspec功能规格(不是在开发模式).此外,通常只有在我运行一个功能规格时才会发生;如果我运行整个测试套件,我通常不会得到错误.

由于此提交到Rails,发生错误
https://github.com/rails/rails/commit/b33700f5580b4cd85379a1dc60fa341ac4d8deb2

但是,当然,我不知道这是真正的问题,还是在调用堆栈中更深入.我知道,如果我在Rails代码中进行最小的更改,以免抛出该错误,一切似乎都可以正常工作,我的测试通过.但是,某处,似乎正在尝试加载LocationsController,即使它已经加载.

任何帮助都非常感激,因为这个我真的很难受.

1) Locations Creating locations
     Failure/Error: Unable to find matching line from backtrace
     RuntimeError:
       Circular dependency detected while autoloading constant LocationsController
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/dependencies.rb:460:in `load_missing_constant'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/dependencies.rb:183:in `const_missing'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/inflector/methods.rb:226:in `const_get'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/inflector/methods.rb:226:in `block in constantize'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/inflector/methods.rb:224:in `each'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/inflector/methods.rb:224:in `inject'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/inflector/methods.rb:224:in `constantize'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/dependencies.rb:534:in `get'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/dependencies.rb:565:in `constantize'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/routing/route_set.rb:76:in `controller_reference'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/routing/route_set.rb:66:in `controller'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/routing/route_set.rb:44:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/journey/router.rb:71:in `block in call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/journey/router.rb:59:in `each'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/journey/router.rb:59:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/routing/route_set.rb:655:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/request_store-1.0.5/lib/request_store/middleware.rb:9:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/warden-1.2.1/lib/warden/manager.rb:35:in `block in call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/warden-1.2.1/lib/warden/manager.rb:34:in `catch'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/warden-1.2.1/lib/warden/manager.rb:34:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/middleware/flash.rb:241:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/middleware/cookies.rb:486:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activerecord/lib/active_record/query_cache.rb:36:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/callbacks.rb:373:in `_run__1828229838678430325__call__callbacks'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/callbacks.rb:80:in `run_callbacks'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/railties/lib/rails/rack/logger.rb:38:in `call_app'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/railties/lib/rails/rack/logger.rb:21:in `block in call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/tagged_logging.rb:67:in `block in tagged'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/tagged_logging.rb:25:in `tagged'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/tagged_logging.rb:67:in `tagged'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/railties/lib/rails/rack/logger.rb:21:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/quiet_assets-1.0.2/lib/quiet_assets.rb:18:in `call_with_quiet_assets'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/middleware/request_id.rb:21:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/middleware/static.rb:64:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/railties/lib/rails/engine.rb:511:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/railties/lib/rails/application.rb:97:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/urlmap.rb:65:in `block in call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `each'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/capybara-2.1.0/lib/capybara/server.rb:19:in `call'
     # /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
     # /usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
     # /usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
     # /usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

routes.rb中:

get '/locations',to: 'main#index',:as => :em_locations

scope 'api' do
  resources :locations,only: [:index]
end

相关宝石:

* capybara (2.1.0)
  * rspec (2.13.0)
  * rspec-core (2.13.1)
  * rspec-expectations (2.13.0)
  * rspec-mocks (2.13.1)
  * rspec-rails (2.13.2)
  * ember-data-source (0.0.5)
  * ember-rails (0.12.0)
  * ember-source (1.0.0.rc3.3)
  * active_model_serializers (0.8.1)

我试过的

>更改我的路线的名称和路径,认为垃圾/位置可能是冲突的.
>更改了一些我认为可能相关的不同的Rails选项.实际上,如果我在test.rb env文件中设置config.cache_classes为false,它解决了这个问题,尽管这个规范的运行速度要慢5倍.

这是我正在运行的规范:

require 'spec_helper'

feature 'Locations',js: true,strategy: :truncation,slow: true do

  before do
    login_for_request
    Factory.create(:warehouse,code: "TW",name: 'TEST WAREHOUSE')
  end

  scenario "Creating locations" do
    visit em_locations_path
    click_link "create-locations"
    select 'TEST WAREHOUSE',from: "warehouse"
    select "GLD",from: "section"
    fill_in "row-start",with: "AA"
    fill_in "row-end",with: "AB"
    fill_in "bay-start",with: "1"
    fill_in "bay-end",with: "2"
    fill_in "tier-start",with: "1"
    fill_in "tier-end",with: "2"
    fill_in "subbay-start",with: "1"
    fill_in "subbay-end",with: "2"
    click_button "Create"
  end


end

解决方法

我想出了一个可能的解决方案来解决这个问题.这可能不是最好的方法,我不认为这是必要的,但是它的作品和作品一贯.

在我的功能规格中,我需要相关的控制器:

require_relative '../../app/controllers/locations_controller'

还需要在控制器中要求active_model_serializer:

require_relative '../serializers/location_serializer'

我当然欢迎更好的解决方案.在此期间,我的规格正在过去.

原文链接:https://www.f2er.com/ruby/274021.html

猜你在找的Ruby相关文章