在我的 Rails 应用程序中,页面顶部有以下链接:
<ul>
<li><%= link_to 'Group Chairperson', '#group_chair' %></li>
<li><%= link_to 'Group Treasurer', '#group_treasurer' %></li>
<li><%= link_to 'Group Secretary', '#group_secretary' %></li>
</ul>
在页面下方,我有以下表格行选择器:
<tr id="group_chair">
单击“小组主席”链接会使浏览器按预期向下滚动到正确的表格行。现在我想制定一个测试这个特性的规范。我尝试了以下方法:
require 'spec_helper'
describe "Group officer duties page" do
before { visit group_officer_duties_path }
it "should scroll down to the right section" do
click_link "Group Chairperson"
expect(current_url).to eq "http://www.example.com/group_officer_duties#group_chair"
end
end
我希望这个测试能够通过,因为这是我的浏览器的 URL 栏在单击正确链接后显示的内容。但是,我实际上得到了这个:
Failures:
1) Group officer duties page should scroll down to the right section
Failure/Error: expect(current_url).to eq "http://www.example.com/group_officer_duties#group_chair"
expected: "http://www.example.com/group_officer_duties#group_chair"
got: "http://www.example.com/group_officer_duties"
(compared using ==)
# ./spec/requests/group_officer_duties_nav_spec.rb:9:in `block (2 levels) in <top (required)>'
Finished in 0.94885 seconds
1 example, 1 failure
知道这是怎么回事吗?