#mtanzi-ruby-mock

1 messages ยท Page 1 of 1 (latest)

sour steeple
weary geode
#

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?

sour steeple
#

@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

weary geode
#

Do you have a way internally to stub those object? something similar to instance_double ?

sour steeple
#

@weary geode orakaro will step in here since he's more familiar with ruby. Give him a second to catch up with the conversation

lapis wraith
#

Hi @weary geode

weary geode
#

Hi!

lapis wraith
#

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

GitHub

A mocking library for testing stripe ruby. Contribute to stripe-ruby-mock/stripe-ruby-mock development by creating an account on GitHub.

weary geode
#

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...

lapis wraith
#

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

weary geode
lapis wraith
#

ah

#

๐Ÿ‘

#

That's used in testing on stripe gem as well

weary geode
#

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 ๐Ÿ‘

lapis wraith
#

You have found it yourself!

sour steeple
#

yeah, i can't take credit at all lol

#

many thanks to @lapis wraith for jumping in too

lapis wraith
#

me neither!