简体   繁体   English

RSpec中的堆栈级别太深

[英]stack level too deep in rspec

When I try to perform following code on specs it gives me stack level too deep . 当我尝试在规格上执行以下代码时,它会使我的stack level too deep Works fine in the console. 在控制台中工作正常。

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

How should I fix it to avoid stack level too deep ? 我应该如何解决它,以避免stack level too deep

You have a bug in your code, last line of the select_reconciliation? 您的代码中有错误, select_reconciliation?最后一行select_reconciliation? method after the || ||之后的方法 you have order_fulfillments_without_receipts but I think you meant @order_fulfillments_without_receipts 您有order_fulfillments_without_receipts但我认为您的意思是@order_fulfillments_without_receipts

Without the @ you're calling the order_fulfillments_without_receipts method, hence the infinite loop. 如果没有@您将调用order_fulfillments_without_receipts方法,因此将导致无限循环。

Why this is happening in your tests and not in your console must be to do with what receipt_urls_empty is in each case, in your tests it's false and in your console it's true . 为什么在您的测试中而不是在控制台中发生这种情况,必须与每种情况下的receipt_urls_empty ,在测试中它为false ,在控制台中为true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM