Capybara 使用 :js=>true 进行测试...路由错误:没有路由匹配 [GET] "/assets"; [英] Capybara tests with :js=>true... Routing Error: No route matches [GET] "/assets"

查看:29
本文介绍了Capybara 使用 :js=>true 进行测试...路由错误:没有路由匹配 [GET] "/assets";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我向它们添加 ":js => true" 时,我在许多测试中遇到了类似的错误.例如:

I'm getting a similar error in a number of tests when I add ":js => true" to them. eg:

    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 文件中添加了一些之前/之后的钩子(钩子?)/rspec-rails-capybara-different-failures-with-js-true-and-without">此处.

I haven't been testing JavaScript-enabled stuff in my app before and have only just set up to do so by upgrading to Capybara 2 and installing Database Cleaner. config.use_transactional_fixtures = false, and I've added some before/after hooks (hooks?) to my spec_helper file that I've copied directly from the accepted answer here.

我正在跑步:

  • Rails 3.2.5
  • Rspec-rails 2.12.2.

谁能告诉我如何攻击这个?非常感谢!

Can anyone clue me in on how I can attack this one? Many thanks!

    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'

推荐答案

您缺少的路由看起来像是一些自动生成的资产路径,输入为零.您确定您的资产在您的 css/sass 或这条路线来自的任何地方正确指定吗?

Your missing route looks like some auto-generated assets path with nil input. Are you sure your assets are correctly specified in your css/sass or wherever this route comes from?

我一直在为资产路径导致路由错误的类似问题而苦苦挣扎

I have been struggling with a similiar issue where an asset path induced a routing error

  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"

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

followed by a stack trace virtually identical to yours. In my case it turned out the asset was in fact missing (which went unnoticed in my development.log and in my test environment until recently I recklessly 'bundle updated' an project after several idle months)

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

Along the way I learned a lot about Capybara's app_host and asset handling, assets precompiling in different environments, Application.configure.assets.[debug|digest|...] and alike, which probably is where you should be searching in the first place. Or in the sprockets/sass-rails url helper ... after all your missing route still looks like some auto-generated assets path with empty input)

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

If the above doesn't help a workaround might be adding the following line in environments/test.rb:

config.action_dispatch.show_exceptions = true

虽然没有直接解决问题,但在我的情况下它成功地抑制了它.

While not addressing the problem directly, it successfully suppressed it in my case.

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

Another kind of workaround could be in spec_helper.rb:

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

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

where myapp.dev is a running instance of myApp in development mode, which delivers the assets or at least does not hit your test routing for the assets, but probably one should do this only in complete desparation. It's inspired by the strategy to avoid asset compiling as explained in http://johnbintz.github.com/blog/2012/01/07/cucumber-capybara-asset-pipeline-debug-mode/

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

这篇关于Capybara 使用 :js=>true 进行测试...路由错误:没有路由匹配 [GET] "/assets";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆