Then /^I should be on the free signup page$/ do
*current_path.should == free_signup_path*
end
Then /^I should be on the free signup page$/ do
*visit free_signup_path*
end
這兩個有什麼區別?訪問和current_path和使用.should在rails中有什麼區別?
Then /^I should be on the free signup page$/ do
*current_path.should == free_signup_path*
end
Then /^I should be on the free signup page$/ do
*visit free_signup_path*
end
這兩個有什麼區別?訪問和current_path和使用.should在rails中有什麼區別?
#visit
告訴瀏覽器轉到一個新的URL,並將向正在測試的應用發起獲取請求。 #current_path
可讓您閱讀瀏覽器所在的當前位置。
注意:在驗證當前路徑時,應停止使用current_path.should == some_path
,而應使用page.should have_current_path(some_path)
。 has_current_path匹配器包含等待行爲,並將有助於使測試更輕鬆與JS功能的驅動程序
您可以使用visit
來告訴rspec轉到該路徑以驗證某些工作是否有效。例如:
it 'contains the new sessions form' do
visit 'sessions/new'
current_path.should have_content("Sign In")
end
當然,我的登錄表單有一個按鈕或任何文本「登錄」,這個測試會通過。
您通常必須聲明測試應該通過什麼路徑來檢測內容。
希望這會有所幫助!
謝謝湯姆的幫助。 – tanay