Question

I'm trying to test my payment process and I'm stuck with the problem of stubbing the subscription, this is the error message I get :

Double "Stripe::Customer" received unexpected message :[] with ("subscription")

This is the relevant part of the code for stubbing subscription :

@subscription = double('Stripe::Subscription')
@subscription.stub(:id) { 1234 }
@customer.stub(:subscription) { [@subscription] }

When I try the payment with the test card and it works, but I want to have an automated test in place in case something changes which could impact the payments

Edit :

per mcfinnigan suggestion I changed he last bit of code to :

@customer.stub(:[]).with(:subscription).and_return { [@subscription] }

And now I get this error :

Double "Stripe::Customer" received :[] with unexpected arguments
  expected: (:subscription)
       got: ("subscription")
 Please stub a default value first if message might be received with other args as well.
Was it helpful?

Solution

You're not stubbing the right thing - your error indicates that something is attempting to call the method [] (i.e. array or hash dereferencing) on your double @customer.

Check your code and see whether you are sending a [] to a customer object anywhere.

Are you positive the last line should not be

@customer.stub(:[]).with(:subscription).and_return { [@subscription] }

instead?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top