0
私はRSpecを初めて使い、モックでのテスト方法に苦しんでいます。ウェブフックが入って来たときに 。これは基本的に呼ばれている。複雑なケースのRspec
class InvoiceCreated
def call(event)
invoice = event.data.object
# NOTE: Skip if the invoice is closed.
if invoice.closed == false
stripe_customer = invoice.customer
payment_account = PaymentCardAccount.find_by(stripe_customer_id: stripe_customer)
card_invoice = Invoice.find_card_invoice_in_this_month_within(payment_account: payment_account)
card_invoice.process_invoice_items(stripe_customer: stripe_customer,
event_invoice_id: invoice.id)
card_invoice.process!(:pending, id: invoice.id)
end
end
end
私はモックを使用して、以下の2行のコードをテストするために呼び出すAPIを防ぐのが大好きです。
card_invoice.process_invoice_items(stripe_customer: stripe_customer,
event_invoice_id: invoice.id)
card_invoice.process!(:pending, id: invoice.id)
モックを使用するにはどうすればよいですか?
どのrspecのバージョンを使用していますか? – hakcho
私は 'rspec-rails'、 '〜> 3.4.2'を使用します。 – Tosh
"モック"と言うと、実際にここで何を達成しようとしていますか? 'NoMethodError:Undefined method process_invoice_items'のようなエラーで失敗することはありません。または、実際に請求書を処理するWeb API呼び出しをスタブアウトしたいのですが、そうでなければこの機能の「完全なテスト」を実行しますか?このテストは何を達成しようとしていますか? (おそらく、上記のポストに現在のテストを含めることができますか?) –