如何让黄瓜显示完整(rails)错误消息?
似乎 cuke 没有显示完整的错误消息(至少当模板中出现问题时),这使得定位问题非常困难。
这是它在某些错误时输出的内容:
... And I am on checkout page # features/step_definitions/webrat_steps.rb:6 You have a nil object when you didn't expect it! The error occurred while evaluating nil.items (ActionView::TemplateError) features/manage_orders.feature:9:in `And I am on checkout page' ...
这是当在浏览器中重现相同问题时 Rails 显示的内容:
Showing app/views/cart/show.erb where line #46 raised:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.items
Extracted source (around line #46):
43: </script>
44:
45: <% ths = %w{th_title th_price th_subtotal th_quantity}.collect {|th| t th.intern} %>
46: <% table(@cart.items, ths) do |cart_item, style| -%>
47: <tr class="<%= style %>">
48: <td width="60%"><%=h cart_item.title %></td>
49: <td width="20%"><%=number_to_currency cart_item.price %></td>
前者有点太简洁了。 cucumber.log 也不例外。 我的模板有一些部分和布局。 没有任何线索,相当调查。
是否有任何秘密插头可以拔出以使黄瓜显示完整错误?
Seems like cuke doesn't show the full error message (at least when problem occurs in template) which makes it really hard to locate the problem.
Here is what it outputs on some error:
... And I am on checkout page # features/step_definitions/webrat_steps.rb:6 You have a nil object when you didn't expect it! The error occurred while evaluating nil.items (ActionView::TemplateError) features/manage_orders.feature:9:in `And I am on checkout page' ...
And here is what rails shows when the same problem is reproduced in browser:
Showing app/views/cart/show.erb where line #46 raised:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.items
Extracted source (around line #46):
43: </script>
44:
45: <% ths = %w{th_title th_price th_subtotal th_quantity}.collect {|th| t th.intern} %>
46: <% table(@cart.items, ths) do |cart_item, style| -%>
47: <tr class="<%= style %>">
48: <td width="60%"><%=h cart_item.title %></td>
49: <td width="20%"><%=number_to_currency cart_item.price %></td>
The former is a bit too neat. No exception in cucumber.log either. And my template has got few partials and a layout. Given no clues, quite an investigation.
Is there any secret plug to pull to get cucumber show full error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正确的答案(感谢 cuke google group)是在运行 cucumber 时使用
--backtrace
选项。Correct answer (thanks to cuke google group) is using
--backtrace
option when running cucumber.您可以在 features/support.env 中注释掉以下行以使用 Rails 错误处理。
您还可以使用 tail -f log/test.log 来监视日志。
You could comment out following line in your features/support.env to use Rails error handling.
You could also use tail -f log/test.log to keep an eye on the logs.
也许没有太大帮助,但 @cart 对象似乎没有被实例化。 检查你的控制器是否如此。
Maybe not much help but the @cart object does not seem to have been instantiated. Check out your controller so that it is.