簡體   English   中英

Rspec檢查塊是否具有正確參數的yield

[英]Rspec check if a block is yield with correct arguments

我想檢查status_params是否通過以及是否正確:

  def send_push_notification(order, parse_events)
    Parse.publish_status(order.deliverer_id) do
      status_params(
        parse_events[:role],
        order,
        generate_message(message)
      )
    end
  end

  def status_params(role, order, message)
    {
      role: role,
      status: order.status,
      order_id: order.id,
      alert: message
    }
  end

到目前為止,我的rspec:

      it 'sends push notification to the deliverer when the order is ready' do
        expect(Parse).
          to receive(:publish_status).with(order.deliverer_id).once
        subject.update_order(
          order,
          status: 'ready'
        )
      end

因此它僅檢查deliverer_id是否通過。 那塊呢? 我需要確保這些是正確的論點。 請幫忙!

您可以使用塊實現自己調用傳遞的塊,以檢查其結果:

expect(Parse).to receive(:publish_status).with(order.deliverer_id).once do |&block|
  result = block.call
  expect(result).to be_a(Hash)
  expect(result[:status]).to eq('ready')
  # ...
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM