0
在我的Rails應用程序中,我試圖做一個基本的測試,測試在文件夾創建後,用戶被重定向到文件夾顯示頁面。我已經實現這個代碼,當我做這一切通過瀏覽器但測試失敗,給我這個錯誤它的工作原理:Rspec redirect_to'Array with Array field'比較錯誤
Failure/Error: response.should redirect_to folder_path(folder)
ArgumentError:
comparison of Array with Array failed
我開了撬這種試塊,這是什麼話也說:
ArgumentError: comparison of Array with Array failed
from /Users/XXXX/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.0/lib/action_dispatch/journey/formatter.rb:43:in `sort'
任何人都知道爲什麼會出現此錯誤? 下面是參考試塊:
context "with valid inputs" do
let(:alice) { Fabricate(:user) }
let(:folder) { Fabricate.attributes_for(:folder) }
before do
login_user(alice)
post :create, folder: folder
end
it "redirects to the folder show page" do
response.should redirect_to folder_path(folder)
end
和相應的控制器代碼:
def create
new_folder(folder_params)
if @folder.save
flash[:success] = "Folder Created"
redirect_to folder_path(@folder)
else
flash[:danger] = "An Error occured."
render :new
end
end
你知道哪個換行符在您的測試,並在你的控制器? – Chambeur 2015-04-01 10:01:05
@Chambeur是它的行'response.should redirect_to folder_path(folder)' – Harazzy 2015-04-01 10:30:39
'Fabricate.attributes_for(:folder)'的返回類型是什麼?你確定它可以正常使用'folder_path'嗎? – Chambeur 2015-04-01 10:53:40