How to mock Stripe::Charge.retrieve using Stripe Mock gem

I created customer, made a subscription on the behalf of the customer. Along with that I generated invoices and expected in the RSpec example like

 

it 'should make sure reward amount in transaction history is equal \
    to amount added by the supporter.' do
  invoice = customer.invoices.first
  invoice.pay
  charge = Stripe::Charge.create(customer: customer.id, amount: invoice.total, currency: 'usd').to_h
  charge[:id] = invoice.charge
  charge = RStruct.new(charge)
  allow(Stripe::Charge).to receive(:retrieve).and_return(charge) # A mock object would be more useful here.
  execution
  expect(TransactionHistory.first.added_rewards).to eq(invoice.total/100.0)
end

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s