Question

I have a cucumber test which tests a user adding paypal pre-approval. In my controller, I redirect to the paypal pre-approval url.

if @payment_method.valid?
  key = @payment_method.preapprove_paypal
  redirect_to URI.encode("#{Rails.configuration.paypal.preapproval_link}#{key}")
end

So in my cucumber test I wanted to stub the redirect out (using Webmock) to avoid dependency on the paypal site in my tests and have it just go back to my app as if it was a success.

stub_request(:any, /.*paypal.*/).to_return{current_url}

However, this seems to be giving me a timeout. I'm not quite sure the way I'm approaching it is correct. Any ideas what I could be doing wrong?

Was it helpful?

Solution

So I solved it by moving my redirect to a separate method:

def redirect_to_paypal_preapproval(key)
 redirect_to URI.encode("#{Rails.configuration.paypal.preapproval_link}#{key}") 
end

Then in my cucumber test I put:

PaymentMethodsController.stub(:redirect_to_paypal_preapproval)
  .and_return(visit payment_methods_path)

That seemed to redirect on it's own back to my app as if the approval was a success

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top