[rspec-users] how can I stub out external service calls during integration tests?

Patrick J. Collins patrick at collinatorstudios.com
Thu Apr 19 06:33:50 UTC 2012


Hi,

I realize that integration tests are supposed to be high-level and deal
with what the user really sees on their end, but say you have a form
that integrates via ajax with a payment service like chargify--  Even
though that service may have a "sandbox" environment that you can post
to, I would rather not my requests specs go out and actually hit the
wire...

So, my question is, what is the proper way to stub out something like
this?  Is it to do something hacky like:

page.evaluate_script "$('#form_for_chargify').submit(function() {
window.location = '<<some path where a user is redirected to upon successful payment>>'; return false; }

Is there a better way to do this?

Thanks.

Patrick J. Collins
http://collinatorstudios.com



More information about the rspec-users mailing list