2010-06-04 17 views
8

我正在爲使用webrat的rails應用程序編寫集成測試。填寫表格後,用戶按下提交併創建一個帳戶。Webrat和Rails:在click_button後使用assert_contain給我「你正在重定向」

click_button "Submit" 
assert_contain "Your Account Has Been Created" 

然而,該測試失敗:

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

通常遵循一個重定向我會用post_via_redirect,但只是看着Webrat的例子,click_button其次assert_contain應該工作

我只是開始使用Webrat,所以我在這裏錯過了一些明顯的東西?爲什麼我堅持使用重定向響應?

謝謝!

Deb

回答

11

隨着新的Rails 3應用程序,我也有這個問題測試一個簡單的方法,其中包括在控制器中的redirect_to調用。該方法本身運行良好,但Webrat會返回「您正在重定向」。響應。

在黃瓜中添加一個'然後顯示我的頁面'步驟(因此webrat看到的頁面在瀏覽器中打開)顯示'您正在被重定向。「響應,並鏈接到example.org鏈接

在此基礎上,我發現Yannimac的補丁(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 

進行這些更改固定的問題,所以redirect_to的與webrat電話現在可以正常工作

+0

補丁完美的作品 – 2010-11-24 15:28:32

+2

你也可以使用''follow_redirect有 – Rob 2010-12-03 16:40:11

+0

......與此問題的不完全100%它不趕上'redirect_to的:back' – Rob 2010-12-03 17:39:56

0

您是否在應用程序中有任何身份驗證?我認爲重定向是因爲你沒有被認證。如果我的假設是正確的,寫一個設置首先登錄Webrat。

相關問題