2013-12-19 46 views
4

我已經中Rspec的以下Rspec的 - redirect_to的路徑相匹配的正則表達式

response.should redirect_to %r{\A/my_settings/mysub_path/} 

我收到以下錯誤

NoMethodError: undefined method `model_name' for Regexp:Class 

我只需要配合我的路徑的一部分,其中包含my_settings/mysub_path。 rspec如何實現?

回答

4

redirect_to需要一個字符串或活動記錄模型。

,如果你想匹配的東西,你可以使用response.location

6

要檢查對正則表達式的重定向做一個字符串匹配的response.location,像這樣:

expect(response.location).to match('your_expected_location.com') 
1

這裏的另一種簡單的方法要做到這一點:

response.location.should =~ /whatever_you_want_to_match/ 
+0

我認爲「應該」的語法不贊成「期望」。 –

相關問題