true”时,我在许多测试中遇到了类似的错误。例如: An error occurred in an after hook ActionControl-6ren">
gpt4 book ai didi

ruby-on-rails-3 - Capybara 测试 :js=>true. .. 路由错误:没有路由匹配 [GET] "/assets"

转载 作者:行者123 更新时间:2023-12-03 07:03:16 27 4
gpt4 key购买 nike

当我向其中添加“:js => true”时,我在许多测试中遇到了类似的错误。例如:

    An error occurred in an after hook
ActionController::RoutingError: No route matches [GET] "/assets"
occurred at /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'

我之前没有在我的应用程序中测试过支持 JavaScript 的内容,只是通过升级到 Capybara 2 并安装 Database Cleaner 来进行测试。 config.use_transactional_fixtures = false,并且我在我的spec_helper文件中添加了一些之前/之后的钩子(Hook)(钩子(Hook)?),我直接从接受的答案here复制该文件。 .

我正在运行:

  • Rails 3.2.5
  • Rspec-rails 2.12.2。

有人可以告诉我如何攻击这个吗?非常感谢!

    4) Event pages 'CREATE' submitting a valid form provides a success notification and displays new event's page 
Failure/Error: Unable to find matching line from backtrace
ActionController::RoutingError:
No route matches [GET] "/assets"
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/railties-3.2.5/lib/rails/rack/logger.rb:26:in `call_app'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/railties-3.2.5/lib/rails/rack/logger.rb:16:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/request_id.rb:22:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/activesupport-3.2.5/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/static.rb:62:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/railties-3.2.5/lib/rails/engine.rb:479:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/railties-3.2.5/lib/rails/application.rb:220:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/builder.rb:134:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/urlmap.rb:64:in `block in call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/urlmap.rb:49:in `each'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/urlmap.rb:49:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/bundler/gems/capybara-8368069cfd05/lib/capybara/server.rb:19:in `call'
# /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
# /Users/appletart/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
# /Users/appletart/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
# /Users/appletart/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

最佳答案

您丢失的路线看起来像是一些输入为零的自动生成的 Assets 路径。您确定您的 Assets 在您的 css/sass 中或该路线来自的任何地方正确指定吗?

我一直在努力解决类似的问题,即 Assets 路径引发路由错误

  1) user signup: [ JS ] : creates User on successful signup
Failure/Error: Unable to find matching line from backtrace
ActionController::RoutingError:
No route matches [GET] "/assets/images/leftArrow.png"

后跟与您的堆栈跟踪几乎相同的堆栈跟踪。就我而言,事实证明该 Assets 实际上丢失了(这在我的development.log和我的测试环境中都没有被注意到,直到最近我在闲置几个月后鲁莽地“捆绑更新”了一个项目)

一路上,我学到了很多关于 Capybara 的 app_host 和 Assets 处理、不同环境中的 Assets 预编译、Application.configure.assets.[debug|digest|...] 等方面的知识,这可能是您应该搜索的地方第一名。或者在sprockets/sass-rails url helper中......毕竟你丢失的路线看起来仍然像一些带有空输入的自动生成的 Assets 路径)

如果上述方法没有帮助,解决方法可能是在environments/test.rb中添加以下行:

config.action_dispatch.show_exceptions = true

虽然没有直接解决问题,但在我的例子中它成功地抑制了它。

另一种解决方法可以在spec_helper.rb中:

 ActionController::Base.asset_host = "http://myapp.dev"

其中 myapp.dev 是 myApp 在开发模式下的运行实例,它提供 Assets 或至少不会影响 Assets 的测试路由,但可能只有在完全绝望的情况下才应该这样做。它的灵感来自于避免 Assets 编译的策略,如中所述 http://johnbintz.github.com/blog/2012/01/07/cucumber-capybara-asset-pipeline-debug-mode/

也可能有帮助: http://guides.rubyonrails.org/asset_pipeline.html http://rubydoc.info/github/jnicklas/capybara/master/Capybara#configure-class_method

关于ruby-on-rails-3 - Capybara 测试 :js=>true. .. 路由错误:没有路由匹配 [GET] "/assets",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14629491/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com