【问题标题】:How to make cucumber show full (rails) error message?如何让黄瓜显示完整(rails)错误消息?
【发布时间】:2009-06-29 21:49:35
【问题描述】:

似乎 cuke 没有显示完整的错误消息(至少在模板中出现问题时),这使得很难找到问题。

这是它在某些错误时输出的内容:

... 我在结帐页面# features/step_definitions/webrat_steps.rb:6 当你没想到时,你有一个 nil 对象! 评估 nil.items 时发生错误 (ActionView::TemplateError) features/manage_orders.feature:9:in `我在结帐页面上' ...

这是在浏览器中重现相同问题时 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 中也不例外。而且我的模板很少有部分和布局。没有任何线索,相当调查。

有没有什么秘密插件可以让黄瓜显示完整错误?

【问题讨论】:

  • 你的问题标题会是一首好歌曲或电视剧集的标题,但不是一个 SO 问题,所以我修改了它:)

标签: ruby-on-rails testing cucumber integration-testing


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    Cucumber::Rails.bypass_rescue
    

    您也可以使用 tail -f log/test.log 来查看日志。

    【讨论】:

      【解决方案3】:

      也许没有太大帮助,但 @cart 对象似乎没有被实例化。检查你的控制器,这样它就可以了。

      【讨论】:

      • 问题不在于错误本身,而在于 cuke 对报告细节没有帮助。
      • 很抱歉。好吧,你几乎得到了 Rails 错误和测试的行号。有人可能会认为 nil.Items 中的 nil 变量名可能已经以某种方式插入其中,但否则我不知道 Cucumber 还能期待什么?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-04
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      相关资源
      最近更新 更多