【发布时间】:2016-01-23 15:02:05
【问题描述】:
在 Michael Hartl 的 Ruby on 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
【问题讨论】:
标签: ruby-on-rails