#mtanzi-ruby-mock
1 messages ยท Page 1 of 1 (latest)
the object that I would like to mock has the following shape:
#<Stripe::Subscription:0xffa0 id=test_sub_1> JSON: {...}>
what do you reckon is the best way to mock it using the rspec tools?
@weary geode sorry, i don't have an answer for you really ๐
we don't have any official libraries for mocking so perhaps your best bet may be to try using another 3rd party gem or perhaps reach out to the creator of that gem to see if there's any timeline as to when they would be able to mock the particular objects you need
Do you have a way internally to stub those object? something similar to instance_double ?
@weary geode orakaro will step in here since he's more familiar with ruby. Give him a second to catch up with the conversation
Hi @weary geode
Hi!
Like alex states we don't currently have an official support mocking library. I am looking at stripe-ruby-mock and it's quite interesting. Are you trying to mock the Subscription? How was their subscription api? https://github.com/stripe-ruby-mock/stripe-ruby-mock/blob/master/lib/stripe_mock/request_handlers/subscriptions.rb
I was looking at the Stripe gem and I might have just found a lead actually ๐
something on those lines could work?
Stripe::Subscription.construct_from({id: 'sub_1', cancelled: nil, status: 'active'})
=> #<Stripe::Subscription:0x10090 id=sub_1> JSON: {
"id": "sub_1",
"cancelled": null,
"status": "active"
}
the problem with stripe-ruby-mock is related to the subscription object... they support the plan, but not the product-price combination which is the new way Stripe allow to define a plan
I could fork it and push the changes but I would rather not use a for in our project...
I see. Unfortunately there isn't an "official"/"recommend" way from us. Personally I am interested tho ๐ That construct_from is a Rail method, correct? I see you successfully created the object, but not sure if it has the parameters you want
I believe construct_from is part of stripe ruby gem
https://github.com/stripe/stripe-ruby/blob/master/lib/stripe/stripe_object.rb#L85
it's a bit tedious to stub them like this but I believe for now it can do the job
๐
Thanks for the support @lapis wraith and @sour steeple ๐
You have found it yourself!
yeah, i can't take credit at all lol
many thanks to @lapis wraith for jumping in too
me neither!