I'm trying to stub out the Stripe API using Rspec and I'm running into an issue. Here's what my code looks like:
Stripe::Customer.should_receive(:create).with(any_args).and_raise(Stripe::CardError)
Here's the error I'm getting:
Failure/Error: Stripe::Customer.should_receive(:create).with(any_args).and_raise(Stripe::CardError)
ArgumentError:
wrong number of arguments (0 for 3..6)
Stripe::CardError requires 3..6 arguments, per the following source code:
class CardError < StripeError
...
def initialize(message, param, code, http_status=nil, http_body=nil, json_body=nil)
Here's the key documentation from the RSpec doc at github:
expect(double).to receive(:msg).and_raise(error)
#error can be an instantiated object or a class
#if it is a class, it must be instantiable with no args
Since you're just providing the class and the class requires arguments, it's failing. You need to instantiate it (i.e. via new
) and provide arguments.
Full definition is in https://github.com/stripe/stripe-ruby/blob/0c281891948a793e79cc997d31918ba7f987f7ae/lib/stripe/errors/card_error.rb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With