RailsTutorial.org 学习 Rails 5.3.4 布局 link 测试
RailsTutorial.org Learning Rails 5.3.4 Layout link tests
虽然遵循教程 5.3.4 布局 Link 测试失败。
这是测试运行:
$ rails generate integration_test site_layout
这是收到的错误:
/usr/local/rvm/gems/ruby-2.2.1/gems/fog-1.23.0/lib/fog/rackspace/mock_data.rb:42: warning: duplicated key at line 80 ignored: "name"
/home/ubuntu/workspace/db/schema.rb doesn't exist yet. Run rake db:migrate to create it, then try again. If you do not intend to use a database, you should instead alter /home/ubuntu/workspace/config/application.rb to limit the frameworks that will be loaded.
开始
FAIL["test_layout_links", SiteLayoutTest, 2015-05-10 20:31:00 +0000]
test_layout_links#SiteLayoutTest (1431289860.34s)
Expected exactly 2 elements matching "a[href="/"]", found 0..
Expected: 2
Actual: 0
test/integration/site_layout_test.rb:8:in `block in <class:SiteLayoutTest>
1/1: [====================================================================================================================] 100% Time: 00:00:00, Time: 00:00:00
Finished in 0.53147s
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips
这是在 运行 测试和收到错误之前更改的文件 (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
# test "the truth" do
# assert true
end
end
我做错了什么?
这是 app/views/layouts/_header.html.erb 文件的代码:
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<%= link_to "sample app", root_path, id: "logo" %>
<nav>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", help_path %></li>
<li><%= link_to "Log in", '#' %></li>
</ul>
</nav>
</div>
</header>
我的问题是当我在 _header
部分而不是 #
中写 root_path 时,我没有删除 ''
。删除这些后一切正常。也不要忘记 _footer
部分。
虽然遵循教程 5.3.4 布局 Link 测试失败。
这是测试运行:
$ rails generate integration_test site_layout
这是收到的错误:
/usr/local/rvm/gems/ruby-2.2.1/gems/fog-1.23.0/lib/fog/rackspace/mock_data.rb:42: warning: duplicated key at line 80 ignored: "name"
/home/ubuntu/workspace/db/schema.rb doesn't exist yet. Run rake db:migrate to create it, then try again. If you do not intend to use a database, you should instead alter /home/ubuntu/workspace/config/application.rb to limit the frameworks that will be loaded.
开始
FAIL["test_layout_links", SiteLayoutTest, 2015-05-10 20:31:00 +0000]
test_layout_links#SiteLayoutTest (1431289860.34s)
Expected exactly 2 elements matching "a[href="/"]", found 0..
Expected: 2
Actual: 0
test/integration/site_layout_test.rb:8:in `block in <class:SiteLayoutTest>
1/1: [====================================================================================================================] 100% Time: 00:00:00, Time: 00:00:00
Finished in 0.53147s
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips
这是在 运行 测试和收到错误之前更改的文件 (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
# test "the truth" do
# assert true
end
end
我做错了什么?
这是 app/views/layouts/_header.html.erb 文件的代码:
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<%= link_to "sample app", root_path, id: "logo" %>
<nav>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", help_path %></li>
<li><%= link_to "Log in", '#' %></li>
</ul>
</nav>
</div>
</header>
我的问题是当我在 _header
部分而不是 #
中写 root_path 时,我没有删除 ''
。删除这些后一切正常。也不要忘记 _footer
部分。