0
在Michael Hartl的Ruby on Rails教程中,作者實現了集成測試以測試佈局鏈接。他使用的語法:Rails集成測試語法
test "layout links" do
是「佈局鏈接」,告知哪些測試正在做讀者的角色,或者是它的代碼的一部分嗎?
再往下,他跑了assert_select
測試是否HREF鏈接工作:
assert_select "a[href=?]", help_path
爲什麼括號[href=?]
並沒有問號起到什麼作用?對於test/integration/site_layout_test.rb
下面
完整代碼:
require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
test "layout links" do
get root_path
assert_template 'static_pages/home'
assert_select "a[href=?]", root_path, count: 2
assert_select "a[href=?]", help_path
assert_select "a[href=?]", about_path
assert_select "a[href=?]", contact_path
end
end
謝謝,這有助於! – strasbal