当我在许多测试中添加":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并安装数据库清理器来完成这项工作。config.use_transactional_fixtures=false,我在spec_helper文件中添加了一些before/after hook(hook?(,这些文件是我直接从这里接受的答案中复制的。
我正在运行:
- 轨道3.2.5
- Rspec导轨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'
您丢失的路由看起来像是一些没有输入的自动生成的资产路径。你确定你的资产在你的css/sass中或这个路由的任何地方都被正确指定了吗?
我一直在努力解决一个类似的问题,即资产路径导致路由错误
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"
然后是一个几乎与您相同的堆栈跟踪。在我的案例中,事实证明资产实际上不见了(这在我的开发日志和测试环境中没有被注意到,直到最近我在几个月的空闲后鲁莽地"捆绑更新"了一个项目(
一路上,我学到了很多关于Capybara的app_host和资产处理、不同环境中的资产预编译、Application.configure.assets.[debug|digest|…]等等,这可能是你应该首先搜索的地方。或者在链轮/sass-rails url助手中。。。在所有丢失的路线看起来仍然像一些自动生成的资产路径(输入为空(
如果以上内容没有帮助,解决方法可能是在environments/test.rb:中添加以下行
config.action_dispatch.show_exceptions = true
虽然没有直接解决这个问题,但在我的情况下,它成功地抑制了它。
另一种变通方法可以是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/
还有潜在的帮助:http://guides.rubyonrails.org/asset_pipeline.htmlhttp://rubydoc.info/github/jnicklas/capybara/master/Capybara#configure-class_method
在我的例子中,添加:
config.assets.debug = true
到config/environments/test.rb
修复它。
文件中说:
您应该不需要更改test.rb。测试环境中的默认值为:config.assets.comfile为true,config.assess.compress、config.asses.debug和config.assetesdigest为false。
但是,至少在我的情况下,我需要改变它…如果有人能解释它为什么有效,我会很高兴。。。
在我的情况下,我得到了
Failure/Error: Unable to find matching line from backtrace
ActionController::RoutingError:
No route matches [GET] "/favicon.ico"
我已经在app/assets/images下放了一个空文件favicon.ico,所以开发服务器很好。但是测试环境不知道如何处理这种情况下的资产。我找到的解决方法是打开静态服务(而不是使用不同的服务器来服务静态资产(。惩罚当然是表演。
in environments/test.rb, set
config.serve_static_assets = true # default is false
在我的例子中,默认的缺失图像被设置为指向s3。我真的不在乎图像是否加载。PhantomJs
具有通过命令行arg --load-images=no
禁用图像加载的选项。
在Poltergeist
中,这可以在注册驱动程序时设置:
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, :phantomjs_options => ['--load-images=no'])
end