Advise a way to test a wrapper on an external service

31 views
Skip to first unread message

Nicholas Wieland

unread,
Feb 19, 2014, 8:15:50 AM2/19/14
to rs...@googlegroups.com
Hi, I'm trying to test an external service. I like my code, I really dislike the tests (probably because I'm not able to write them).


Someone has some examples of "good style" or some advice for me? For example, I really dislike the fact I must stub the whole
class, it seems to me error prone and too verbose.
The pending spec doesn't even pass (that's why it's pending), and I have no idea why I need all that stuff: to me I should only stub
the query method to test it in another spec later, but I'm apparently not able to make it work.

TIA,
  ngw

Aaron Kromer

unread,
Feb 19, 2014, 10:41:22 AM2/19/14
to rs...@googlegroups.com

Just me 2cents:

If you own Google::APIClient then this seems to be a normal mockist approach. If however, you do not own that class, and instead get it from a gem or some other 3rd party dependency, maybe check out VCR. You can then record a live traffic flow then play it back to validate the tests.

Aside from that, you could possibly refactor the tests a bit. One general guide I use is that a test should only have a single expectation. Aside from that, other suggestions would largely be my personal preference. I would stick with whatever guidelines your dev group has set forth.

Aaron



--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/adea0df9-ff10-4c87-af5e-97504ba45a54%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Nicholas Wieland

unread,
Feb 19, 2014, 11:23:48 AM2/19/14
to rs...@googlegroups.com
On Wednesday, February 19, 2014 4:41:22 PM UTC+1, Aaron Kromer wrote:

Just me 2cents:

If you own Google::APIClient then this seems to be a normal mockist approach. If however, you do not own that class, and instead get it from a gem or some other 3rd party dependency, maybe check out VCR. You can then record a live traffic flow then play it back to validate the tests.

Aside from that, you could possibly refactor the tests a bit. One general guide I use is that a test should only have a single expectation. Aside from that, other suggestions would largely be my personal preference. I would stick with whatever guidelines your dev group has set forth.

Hi, I don't own the Google::APIClient, it's an external gem.
How can you put a single expectations in every test if you have to mock the whole service every time? In my example I have to stub 2 calls only to instantiate the Google::APIClient, that's why I think it's a bit too verbose...
Don't worry about guidelines, I'm the whole dev group :p

Thanks,
  ngw

Aaron Kromer

unread,
Feb 19, 2014, 12:39:12 PM2/19/14
to rs...@googlegroups.com
I would use VCR for this. That records the network traffic and allows you to play it back. No need for the doubles then.


--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages