水豚 + RSpec 仅在控制器规格中看到空白页。为什么?
我正在尝试为一个简单的控制器编写控制器规范。但是,Capybara 看不到任何页面内容。但是,在我的浏览器中查看该网站的页面效果很好。我做错了什么?
谢谢!
I'm trying to write a controller spec for a simple controller. However, Capybara isn't seeing any page content. However, looking at the site's pages in my browser works just fine. What am I doing wrong?
T. Hanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要明确告诉您的控制器规范您希望它渲染视图才能使其工作。将您的规范更新为如下所示:
rspec 的 自述文件 中对此进行了描述。有关更详细的视图,请参阅 rspec-rails 的 cucumber “render_views”功能< /a>.
对此,请注意一点。这不是默认行为是有原因的:
spec/integration
而不是spec/controller
。...并不是说你不应该这样做,只是说你应该清楚为什么。
希望有帮助。
You need to explicitly tell your controller spec that you want it to render views in order for this to work. Update your spec to look like this:
This is described in rspec's readme. For a more detailed view, see rspec-rails' cucumber feature for 'render_views'.
Just one word of caution with this. There are reasons why this isn't default behaviour:
spec/integration
rather thanspec/controller
.... Not saying you shouldn't do this, just saying you should be clear why you are.
Hope that helps.