Forum: RSpec I met a trouble: cannot do a form post to an outside website

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ffcc0777b36f700d1c241dfb2a416040?d=identicon&s=25 Newman Huang (rubbit)
on 2008-12-03 11:11
now i use webrat for cucumber scenario testing. i have a page with a
form, which will post to a bank payment gateway. that is,

<form action="http://www.abank.com/pay/blablabla">
   ...
   <input type=submit name="sbm" value="confirm"/>
</form>

my scenario step script is:

==
And I press "confirm"
==

then I got such an error:

"No route matches "/pay/blablabla" with {:method=>:post}..."

i think webrat or rails ignore the "http://www.abank.com" prefix
automatically. and then i wrote a test script

==
get "http://www.abank.com/.."
puts response.body
==

yes, the test result proves the suspicion. i think it should be handled
in the rails testing layer. so, anybody can help me? thanks in advance.
Ffcc0777b36f700d1c241dfb2a416040?d=identicon&s=25 Newman Huang (rubbit)
on 2008-12-05 08:57
Newman Huang wrote:
> now i use webrat for cucumber scenario testing. i have a page with a
> form, which will post to a bank payment gateway. that is,
>
> <form action="http://www.abank.com/pay/blablabla">
>    ...
>    <input type=submit name="sbm" value="confirm"/>
> </form>
>
> my scenario step script is:
>
> ==
> And I press "confirm"
> ==
>
> then I got such an error:
>
> "No route matches "/pay/blablabla" with {:method=>:post}..."
>
> i think webrat or rails ignore the "http://www.abank.com" prefix
> automatically. and then i wrote a test script
>
> ==
> get "http://www.abank.com/.."
> puts response.body
> ==
>
> yes, the test result proves the suspicion. i think it should be handled
> in the rails testing layer. so, anybody can help me? thanks in advance.

I solved this problem by hacking webrat's code. walking around the
requesting from webrat form, and then use Net::HTTP for a substitutor,

require 'net/http'
require 'uri'
require 'nokogiri'

module Webrat
  class Form
    def submit
      if !out_website?(form_action)
        @session.request_page(form_action, form_method, params)
      else
        handle_outwebsite_action(form_action,params)
      end
    end

    def handle_outwebsite_action(form_action,params)
      #...
    end
  end
end

require it before cucumbing.
This topic is locked and can not be replied to.