0

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.
London
  • 14,986
  • 35
  • 106
  • 147

1 Answers1

2

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?

mcfinnigan
  • 11,442
  • 35
  • 28
  • thanks for your response, can you please take a look at my update – London Feb 06 '14 at 16:58
  • @London ok, so you're receiving a string argument instead of a symbol. Change the stub to `@customer.stub(:[]).with("subscription").and_return { [ @subscription] }` – mcfinnigan Feb 06 '14 at 17:06