[英]assert current_path
require 'test_helper'
class MyTest < ActionController::IntegrationTest
test "view posts from login page" do
visit("/logins/new")
find_field('Username').set('abode')
find_field('Password').set('efghi')
click_link_or_button('Login')
#assert current_path == "/logins/new"
assert current_path == "/posts/index"
end
end
在上面的代碼中,第一個斷言通過了,而第二個斷言失敗了。 否則應該發生。 執行click_link_or_button('Login')
我假設頁面登錄。 我究竟做錯了什么?
謝謝!
對於如今正在搜索此問題的任何人-使用Capybara 2.5,您都可以
assert_current_path('/posts/index')
它將使用水豚的等待行為來檢查路徑是否更改為預期的
看來current_path
變量尚未更新其新路徑值。 因此,您需要等待路徑。 我做了兩件事: 修復了一個錯誤,該錯誤導致正確的current_path
變量update和rspec-wait
gem 。 因此,期望代碼如下:
wait_for{ page }.to have_current_path(posts_path)
您實際上想測試什么? current_path不能同時為“ / logins / new”和“ / posts / index”。
我要說的是,將第一個斷言移到訪問步驟之后。 這樣您的測試就有意義了。 如果仍然失敗,則登錄操作不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.