水豚testing:js => true …路由错误:没有路由匹配“/ assets”

当我向他们添加“:js => true”时,我在一些testing中遇到类似的错误。 例如:

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' 

我之前并没有在我的应用程序中testing启用JavaScript的东西,而只是通过升级到Capybara 2并安装数据库清理程序而设置了这样做。 config.use_transactional_fixtures = false,我已经在我的spec_helper文件中添加了一些前/后钩子(hooks?),我直接从接受的答案复制到这里 。

我在跑:

  • 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' 

您的遗漏路线看起来像一些自动生成的资产path与零input。 你确定你的资产是否正确地在你的css / sass中指定,或者这个路由来自哪里?

我一直在努力解决资产path导致路由错误的类似问题

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

其次是一个堆栈跟踪几乎相同的你的。 在我的情况下,事实certificate这个资产实际上是缺失的(在我的开发日志和我的testing环境中没有被注意到,直到最近几个闲置的月份之后,我毫不留情地“捆绑更新”了一个项目)

在这个过程中,我学习了很多有关Capybara的app_host和资产处理,在不同的环境中进行资源预编译,Application.configure.assets [debug | digest | …]等等,这可能是您应该首先search的地方。 或者在sprockets / sass-rails url助手中……所有你的遗漏路线仍然看起来像一些自动生成的资产path与空input)

如果上述方法不能解决环境/ test.rb中添加以下行的问题:

 config.action_dispatch.show_exceptions = true 

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

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

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

其中myapp.dev是开发模式myApp的运行实例,它提供资产或者至less不会触发您的资产的testing路由,但可能只有在完全绝望的情况下才能做到这一点。 它的灵感来源于避免资产编译的策略, 详见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

在我的情况下,增加:

 config.assets.debug = true 

config/environments/test.rb修复它。

在文档中 ,有人说:

你不需要改变test.rb. testing环境中的默认值为:config.assets.compile为true,config.assets.compress,config.assets.debug和config.assets.digest为false。

但是,至less在我的情况下,我需要改变它…如果任何人都可以解释为什么它的工作,我会很高兴…

在我的情况下,我越来越

  Failure/Error: Unable to find matching line from backtrace ActionController::RoutingError: No route matches [GET] "/favicon.ico" 

我已经在app / assets / images下放了一个空文件favicon.ico,所以开发服务器没问题。 但在这种情况下,testing环境不知道如何处理资产。 我find的解决方法是打开静态服务(而不是使用不同的服务器来提供静态资产)。 当然的惩罚就是表演。

  in environments/test.rb, set config.serve_static_assets = true # default is false