我正在做一些條帶集成測試,我想存根/模擬一些端點。我試圖做這樣的:ActionDispatch中的Stubbing方法:: IntegrationTest
Stripe::Charge.stubs(:retrieve).returns({:balance_transaction => 40})
,但我得到以下幾點:
NoMethodError: undefined method `stubs' for Stripe::Charge:Class
什麼的磕碰這個正確的語法? Rails 4,Ruby 2.
編輯:這是我的完整測試方法。基本上,我的payment_succeeded webhook點擊條紋檢索費用,它是相關的餘額交易,以記錄交易費用。我使用stripe_mock來模擬webhook事件,但我寧願使用標準stubbing技術將其餘的部分剔除。請注意,即使當我將其更改爲「存根」時,它也會引發上述相同的錯誤(使用存根代替存根)。
require 'test_helper'
require 'stripe_mock'
class WebhooksTest < ActionDispatch::IntegrationTest
# called before every single test
def setup
StripeMock.start
end
# called after every single test
def teardown
StripeMock.stop
end
test 'invoice.payment_succeeded' do
Stripe::Charge.stubs(:retrieve).returns({:balance_transaction => 40})
event = StripeMock.mock_webhook_event('invoice.payment_succeeded', { :customer => "stripe_customer1", :id => "abc123" })
post '/stripe-events', id: event.id
assert_equal "200", response.code
assert_equal 1, StripeInvoicePayment.count
assert_equal 'abc123', event.data.object.id
end
end
你使用哪個框架?更多的代碼示例可能? – Elyasin
添加了我試圖運行的完整測試 – Msencenb