Rails 教程(第 3 版)集成测试未 运行,因为 css 选择器无效(c9.io?)

Rails Tutorial (3rd Ed) Integration tests not running because of invalid css selector (c9.io ?)

我正在学习 Rails 教程(使用 cloud9 ide) (第 3 版 https://www.railstutorial.org/book/) 我 运行 喜欢一些奇怪的东西。

我刚刚读完第 7 章,现在我注意到我在第 5 章中的一些断言不是 运行 因为 "The assertion was not run because of an invalid css selector."

这是我的 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
    assert_select "a[href=?", signup_path
  end
end

这似乎是一个字符,用于与在中找到的代码进行字符匹配 https://github.com/mhartl/sample_app_3rd_edition/blob/master/test/integration/site_layout_test.rb

我得到的错误如下

DEPRECATION WARNING: The assertion was not run because of an invalid css selector.=======                                           ] 66% Time: 00:00:00,  ETA: 00:00:00
unexpected '$' after '[:equal, "\"/\""]' (called from block in <class:SiteLayoutTest> at /home/ubuntu/workspace/sample_app/test/integration/site_layout_test.rb:7)
DEPRECATION WARNING: The assertion was not run because of an invalid css selector.
unexpected '$' after '[:equal, "\"/help\""]' (called from block in <class:SiteLayoutTest> at /home/ubuntu/workspace/sample_app/test/integration/site_layout_test.rb:8)
DEPRECATION WARNING: The assertion was not run because of an invalid css selector.
unexpected '$' after '[:equal, "\"/about\""]' (called from block in <class:SiteLayoutTest> at /home/ubuntu/workspace/sample_app/test/integration/site_layout_test.rb:9)
DEPRECATION WARNING: The assertion was not run because of an invalid css selector.
unexpected '$' after '[:equal, "\"/contact\""]' (called from block in <class:SiteLayoutTest> at /home/ubuntu/workspace/sample_app/test/integration/site_layout_test.rb:10)
DEPRECATION WARNING: The assertion was not run because of an invalid css selector.
unexpected '$' after '[:equal, "\"/signup\""]' (called from block in <class:SiteLayoutTest> at /home/ubuntu/workspace/sample_app/test/integration/site_layout_test.rb:11)

我发现真正有趣的是,如果我从样式表中删除所有内容,我仍然会遇到同样的错误。

我不知道术语 "about_path"(或任何其他路径符号)在哪里获取 $ 字符。

我是否遗漏了一些明显的东西,当我 google 帮助我追查事情的警告文本时,我找不到任何参考。

您的 a[href] 参数中缺少右方括号。您的代码应如下所示:

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
    assert_select "a[href=?]", signup_path
  end                      
end