2

I'm not particularly familiar with Faraday's stubbing API, but from a casual inspection of that and the source of Balanced::Client, it looks like I'd need to be able to provide my own value for Balanced::Client.conn.

This is a step towards supporting for a stubbed connection mode by a configuration option in library, whereas flipping on that toggle, I could just use Balanced::Client.conn as a handle for stubbing whatever requests I expect to occur during my test.

It would also be super useful to have example response bodies for the various Balanced API calls and/or some builtin stub responses to use as templates for my own stubs.

Does this seem like a reasonable plan, or am I heading in the wrong direction? How do I go about doing this?

Mahmoud Abdelkader
  • 23,011
  • 5
  • 41
  • 54
Brian Moseley
  • 138
  • 1
  • 7

2 Answers2

2

I recommend taking a look at how the unit tests for the balanced-ruby library are written. They use VCR to record and replay network calls.

While not pertinent to your exact question, you can also create one-off instances of objects by using the construct_from_response method on any object that inherits from the Resource class in resource.rb. This allows you to create a single instance of an object like so:

1.9.3p194 :034 > payload = {:name"=>"Bob", :uri=>"/v1/marketplaces/M123/accounts/fake"} 
1.9.3p194 :035 > account = Balanced::Account.construct_from_response payload
1.9.3p194 :036 > account.name
 => "Bob" 

Note that the uri param in the payload is required or else the library will go and try to look the object up from the server.

mjallday
  • 9,796
  • 9
  • 51
  • 71
0

Can do something like this. Use the gem webmock https://github.com/bblimke/webmock

And stub requests yourself:

stub_request(:get,"https://<your secret key>:@api.balancedpayments.com/v1/customers   email=#<test email>")
.with(:headers => {'Accept'=>'*/*',
                   'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
                   'User-Agent'=>'balanced-ruby/0.7.4'})
.to_return(:status => 200, :body => "", :headers => {})
dylanjha
  • 2,303
  • 4
  • 28
  • 47