[英]How can I retrieve and use the ID of a record I've created inside an RSpec/Capybara test?
我正在嘗試訪問在單個測試中創建的對象的頁面。
it "should display some text" do
log_employee_in
create_ticket
visit "/tickets/#{Ticket.last.id}"
page.should have_content 'Some Text'
end
to the one I've just created. 在此測試的范圍內,Ticket.last 我剛剛創建的記錄顯示了該記錄。 完成此單個測試之后,我可以通過發出Ticket.last
在rails測試控制台中檢索正確的記錄。
在當前測試結束之前,似乎記錄並沒有真正保存到數據庫中。
如何在測試中檢索此ID?
我認為實施訪問是不正確的。 如果create_ticket的其他實現是正確的,那么您可以確定。 您可以嘗試以下方法:
it "should display some text" do
log_employee_in
create_ticket
visit ticket_path(Ticket.last.id) # you should be even able to get the ticket with Ticket.last
page.should have_content 'Some Text'
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.