檢查當前路徑是否是特定路徑的代碼是什麼?Ruby on Rails Rspec:你如何檢查當前路徑?
1
A
回答
3
可以使用可變current_path
,如
expect(current_path).to eq '/users'
3
根據您在控制器或視圖中,您有幾個選項。您可以使用current_page?
helper。
current_page?(action: 'process')
# => false
current_page?(controller: 'shop', action: 'checkout')
# => true
current_page?(controller: 'shop', action: 'checkout', order: 'asc')
# => false
current_page?(action: 'checkout')
# => true
current_page?(controller: 'library', action: 'checkout')
# => false
current_page?('http://www.example.com/shop/checkout')
# => true
current_page?('/shop/checkout')
# => true
在控制器中,您通常會針對request.path
字符串進行檢查。
+3
這不是在rspec的工作對我來說。 – Julia
相關問題
- 1. Ruby on Rails - 路由到當前用戶的帖子路徑
- 2. Ruby on Rails RSPEC
- 3. Ruby on Rails目錄路徑
- 4. Ruby on Rails:你如何在命名路線前綴?
- 5. 你把你的路徑放在Cucumber 1.1+ for Ruby on Rails上?
- 6. ruby on rails rspec error
- 7. Rspec 3.0.0 Ruby on rails
- 8. Ruby on Rails RSpec路由失敗
- 9. Ruby on Rails如何獲取當前URL?
- 10. Ruby on Rails:'rails generate plugin'error rspec
- 11. Ruby on Rails的奇怪路線路徑
- 12. Ruby on Rails的:如何檢查名稱
- 13. Ruby on Rails,AJAX檢查
- 14. ruby on rails rspec命令
- 15. Ruby on Rails的改變搜索路徑
- 16. Ruby on Rails的docsplit文件路徑
- 17. Ruby on Rails中的Gem路徑錯誤
- 18. Ruby on Rails中的Bootstrap CSS路徑
- 19. Ruby on Rails在link_to中添加路徑?
- 20. Ruby on Rails的RSPEC唯一性檢查失敗莫名
- 21. Ruby on Rails 3 + Rspec + Capybara:檢查回覆狀態
- 22. Ruby on Rails路線
- 23. Ruby On Rails路線
- 24. Ruby on Rails路線
- 25. Ruby on Rails:你如何獲得以前的URL?
- 26. 在Ruby on Rails中配置路徑和路徑的位置?
- 27. Ruby on Rails - 僅顯示當前日期
- 28. Ruby on Rails中的當前年份
- 29. Ruby on Rails的當前用戶
- 30. 在Ruby On Rails CLI中,如何列出助手路徑?
只有當您使用水豚纔有此功能嗎? – Jerry
不是,它的內置 – kddeisz
它不起作用了 – Extazystas