views:

310

answers:

5

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_button "Submit"
assert_contain "Your Account Has Been Created"

However, the test fails:

expected the following element's content to include "Your Account Has Been Created":
You are being redirected.
<false> is not true.

Normally to follow a redirect I would use post_via_redirect, but from just looking at Webrat's examples, click_button followed by assert_contain should work

I just started using Webrat, so am I missing something obvious here? Why am I stuck with the redirect response?

Thanks!

Deb

A: 

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.

jpartogi
+1  A: 

I'm having the same issue, and the debug output which shows the body content shows the message! I will post a solution if I find one.

Evan
+2  A: 

Hi,

I am having the same issue "You are being redirected.". when running in mode = :selenium

When running in mode = :rails, getting NoMethodError for 'selenium'.

has anyone resolved this issue please help

ajita
+2  A: 

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.

justsee
A: 

Has anybody found a solution yet? I have exactly the same problem as ajita, and justsee's steps don't seem to be working for me.

Suan