Webrat and Rails: Using assert_contain after click_button gives me “You are being redirected”

前端 未结 4 1276
星月不相逢
星月不相逢 2020-12-15 00:22

I\'m writing an integration test for a rails application using webrat. After filling out a form, the user presses submit and an account is created.

click_but         


        
相关标签:
4条回答
  • 2020-12-15 00:55

    There are some issues with rails 3 and webrat. Please see:

    http://baldowl.github.com/2010/12/06/coercing-cucumber-and-webrat-to-cooperate.html

    0 讨论(0)
  • 2020-12-15 00:59

    Here is the gist with exactly what you need to do to solve this problem.

    https://gist.github.com/752766

    0 讨论(0)
  • 2020-12-15 01:08

    Do you have any authentication in your apps? I presume the redirection is because of you have not been authenticated. If my assumption is right, write a setup to login first with Webrat.

    0 讨论(0)
  • 2020-12-15 01:18

    With a new Rails 3 app, I also had this problem testing a simple method which included a redirect_to call in the controller. The method itself worked fine, but Webrat would return the "You are being redirected." response.

    Adding in a 'Then show me the page' step in cucumber (so the page that webrat sees opens in the browser) showed the 'You are being redirected." response with a link to an example.org link.

    Based on this I discovered Yannimac's patch ( http://groups.google.com/group/webrat/browse_thread/thread/fb5ff3fccd97f3df ):

    #/lib/webrat/core/session.rb
    #starting at line 288
    
    def current_host
    - URI.parse(current_url).host || @custom_headers["Host"] || "www.example.com"
    + URI.parse(current_url).host || @custom_headers["Host"] || default_current_host
    end
    
    + def default_current_host
    +   adapter.class==Webrat::RackAdapter ? "example.org" : "www.example.com"
    + end 
    

    Making these changes fixed the issue, so redirect_to calls with Webrat now work correctly.

    0 讨论(0)
提交回复
热议问题