使用 Capybara 测试资产管道
我想使用 Capybara 在 Rails 3.1 应用程序中执行简单的请求规范。标准案例都按预期工作,但是当我想测试资产管道生成的CSS时,我收到以下错误:
Failure/Error: visit '/assets/main.css'
ActionController::RoutingError:
No route matches [GET] "/assets/main.css"
我认为问题是测试环境没有提供完整的服务器,因此也没有Sprockets中间件提供资产。 这个问题有解决办法吗?
编辑:现在可能了! 我们更新到了 Rails 3.2.12 和 Capybara 2.0.2,现在这些资源也可以在功能规范中找到。
I want to do simple request specs in my Rails 3.1 application with Capybara. The standard cases all work as expected, but when I want to test CSS generated by the asset pipeline, I receive the following error:
Failure/Error: visit '/assets/main.css'
ActionController::RoutingError:
No route matches [GET] "/assets/main.css"
I think the problem is that the test environment does not provide a complete server and so also no Sprockets middleware delivering the assets.
Is there a solution to this problem?
EDIT: Now possible!
We updated to Rails 3.2.12 and Capybara 2.0.2, now the assets are also available in the feature specs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Phusion 人员在博客中讨论了 的可能性将资产渲染为字符串:
您也可以在测试中使用它。该解决方案并不理想,并且/因为 Capybara 不再参与,但它有助于在我的特定情况下验证 CSS。欢迎更好的方法!
The Phusion guys blogged about a possibility to render an asset to a string:
You can also use this in tests. The solution is not ideal and/since Capybara isn't involved anymore, but it helps in my specific case to validate CSS. Better approaches are welcome!