Ruby on rails 3 Capybara找不到指向的Rails链接

Ruby on rails 3 Capybara找不到指向的Rails链接,ruby-on-rails-3,capybara,Ruby On Rails 3,Capybara,_header.html.erb <header class="navbar navbar-fixed-top"> <div class="navbar-inner"> <div class="container"> <%= link_to "sample app", root_path, id: "logo" %> <nav> <ul class="nav pull-right

_header.html.erb

<header class="navbar navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container">
      <%= link_to "sample app", root_path, id: "logo" %>
      <nav>
        <ul class="nav pull-right">
          <li><%= link_to "Home", root_path %></li>
          <li><%= link_to "Help", help_path %></li>
          <% if signed_in? %>
            <li><%= link_to "Users", '#' %></li>
            <li id="fat-menu" class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                Account <b class="caret"></b>
              </a>
              <ul class="dropdown-menu">
                <li><%= link_to "Profile", current_user %></li>
                <li><%= link_to "Settings", '#' %></li>
                <li class="divider"></li>
                <li>
                  <%= link_to "Sign out", signout_path, method: "delete" %>
                </li>
              </ul>
            </li>
          <% else %>
            <li><%= link_to "Sign in", signin_path %></li>
          <% end %>
        </ul>
      </nav>
    </div>
  </div>
</header>
失败是:

1) User pages signup with valid information followed by signout
Failure/Error: before ( click_link "Sign out" )
Capybara::ElementNotFound:
no link with title, id, or text 'Sign out' found
(eval):2:in 'click_link'
./spec/requests/user_pages_spec.rb:63:in 'block (5 levels) in (top (required))'

在手动创建用户过程之后,它似乎可以工作。该链接位于下拉菜单中,是否可能与此有关?在mhartlails教程中,他说所有的测试都应该通过。

上一个描述中的
之前的
块还没有创建用户。这就是用户(还不存在)当前未登录的原因,因此没有“注销”链接


一种可能的解决方案是在before块中单击按钮“提交”
。另一种方法是跳过
before
块中的注销,因为此时没有用户登录。

可疑代码显然需要嵌套在前面描述的

        describe "after saving the user" do
            before { click_button submit }
            let(:user) { User.find_by_email('user@example.com') }

            it { should have_selector('title', text: user.name) }
            it { should have_selector('div.alert.alert-success', text: 'Welcome') }
            it { should have_link('Sign out') }

            describe "followed by signout" do
                before { click_link "Sign out" }
                it { should have_link('Sign in') }
            end
        end

是的,它应该嵌套在前面的描述中。我可以确认这也适用于Rails 4版本的教程

        describe "after saving the user" do
            before { click_button submit }
            let(:user) { User.find_by_email('user@example.com') }

            it { should have_selector('title', text: user.name) }
            it { should have_selector('div.alert.alert-success', text: 'Welcome') }
            it { should have_link('Sign out') }

            describe "followed by signout" do
                before { click_link "Sign out" }
                it { should have_link('Sign in') }
            end
        end