【问题标题】:stack level too deep in rspecrspec 中的堆栈级别太深
【发布时间】:2016-10-25 03:28:43
【问题描述】:

当我尝试在规范上执行以下代码时,它给了我stack level too deep。在控制台中运行良好。

def order_fulfillments_without_receipts
      @order_fulfillments_without_receipts = []
      OrderReconciliation.includes(:order_fulfillment).
        where(data_entry_status: OrderReconciliation.data_entry_statuses[:pending_entry]).
        find_in_batches do |group|
          group.select do |reconciliation|
            select_reconciliation?(reconciliation)
          end
        end
      @order_fulfillments_without_receipts
    end

    def select_reconciliation?(reconciliation)
      order_fulfillment = reconciliation.order_fulfillment
      receipt_urls_empty = order_fulfillment.get_receipt_urls.empty?
      order_fulfillment_id = order_fulfillment.id
      @order_fulfillments_without_receipts << order_fulfillment_id
      receipt_urls_empty || order_fulfillments_without_receipts.include?(order_fulfillment_id)
    end
  end

我应该如何解决它以避免stack level too deep

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 rspec


    【解决方案1】:

    你的代码中有一个错误,select_reconciliation? 方法的最后一行 || 之后你有 order_fulfillments_without_receipts 但我认为你的意思是 @order_fulfillments_without_receipts

    如果没有@,您将调用order_fulfillments_without_receipts 方法,因此会出现无限循环。

    为什么在您的测试中而不是在您的控制台中发生这种情况必须与receipt_urls_empty 在每种情况下的含义有关,在您的测试中它是false,而在您的控制台中它是true

    【讨论】:

      猜你喜欢
      • 2012-03-04
      • 2013-10-05
      • 2016-09-10
      • 2015-04-01
      • 1970-01-01
      • 2012-11-30
      • 1970-01-01
      • 2011-11-17
      • 2012-07-24
      相关资源
      最近更新 更多