[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


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

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?


Patrick J. Collins

More information about the rspec-users mailing list