如何让黄瓜显示完整(rails)错误消息?

发布于 2024-07-26 04:25:09 字数 1163 浏览 3 评论 0原文

似乎 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

后知后觉 2024-08-02 04:25:09

正确的答案(感谢 cuke google group)是在运行 cucumber 时使用 --backtrace 选项。

Correct answer (thanks to cuke google group) is using --backtrace option when running cucumber.

贩梦商人 2024-08-02 04:25:09

您可以在 features/support.env 中注释掉以下行以使用 Rails 错误处理。

Cucumber::Rails.bypass_rescue

您还可以使用 tail -f log/test.log 来监视日志。

You could comment out following line in your features/support.env to use Rails error handling.

Cucumber::Rails.bypass_rescue

You could also use tail -f log/test.log to keep an eye on the logs.

无人问我粥可暖 2024-08-02 04:25:09

也许没有太大帮助,但 @cart 对象似乎没有被实例化。 检查你的控制器是否如此。

Maybe not much help but the @cart object does not seem to have been instantiated. Check out your controller so that it is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文