Rspec Ruby on Rails教程第8.2.6章未找到Capybara元素错误+;无方法错误未定义方法它

Rspec Ruby on Rails教程第8.2.6章未找到Capybara元素错误+;无方法错误未定义方法它,rspec,ruby-on-rails-3.2,capybara,Rspec,Ruby On Rails 3.2,Capybara,我正在学习教程,发现了这个错误 Failures: 1) Authentication signin 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'

我正在学习教程,发现了这个错误

Failures:

  1) Authentication signin 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/authentication_pages_spec.rb:48:in `block (4 levels) in <top (required)>'
用户页面规范

require 'spec_helper'

describe "User pages" do

  subject { page }

  describe "signup page" do
    before { visit signup_path }

    it { should have_selector('h1',    text: 'Sign up') }
    it { should have_selector('title', text: full_title('Sign up')) }
  end

  describe "profile page" do
    let(:user) { FactoryGirl.create(:user) }
    before { visit user_path(user) }

    it { should have_selector('h1',    text: user.name) }
    it { should have_selector('title', text: user.name) }
  end

    describe "signup" do

      before { visit signup_path }

      let(:submit) { "Create my account" }

      describe "with invalid information" do
        it "should not create a user" do
          expect { click_button submit }.not_to change(User, :count)
        end
      end

      describe "with valid information" do
        before do
          fill_in "Name",         with: "Example User"
          fill_in "Email",        with: "user@example.com"
          fill_in "Password",     with: "foobar"
          fill_in "Confirmation", with: "foobar"
        end

        it "should create a user" do
          expect { click_button submit }.to change(User, :count).by(1)
        end

        describe "after saving the user" do
          before { click_button submit }
          #let(:user) { User.find_by(email: 'user@example.com') }
          let(:user) { User.where(email: 'user@example.com').first }

          #it { should have_title(user.name) }
          it { should have_selector( "title", :content => user.name)}
          #it { should have_selector('title', text: user.name) }
          it { should have_selector('div.alert.alert-success', text: 'Welcome') }
          it { should have_link('Sign out') }       
        end
      end
   end
 end
require 'spec_helper'

describe "Authentication" do

  subject { page }

  describe "signin page" do
    before { visit signin_path }

    #it { should have_content('Sign in') }
    #it { should have_title('Sign in') }
    it { should have_selector('h1', text: 'Sign in') }
    it { should have_selector('title', text: 'Sign in') }
  end

 describe "signin" do

   before { visit signin_path }

   describe "with invalid information" do
     before { click_button "Sign in" }

     it { should have_selector('title', text: 'Sign in') }
     it { should have_selector('div.alert.alert-error', text: 'Invalid') }

     describe "after visiting another page" do
       before { click_link "Home" }
       it { should_not have_selector('div.alert.alert-error') }
     end
   end

   describe "with valid information" do
     let(:user) { FactoryGirl.create(:user) }
     before do
       fill_in "Email",    with: user.email.upcase
       fill_in "Password", with: user.password
       click_button "Sign in"
     end

     #it { should have_title(user.name) }
     it { should have_selector( "title", :content => user.name)}
     it { should have_link('Profile',     href: user_path(user)) }
     it { should have_link('Sign out',    href: signout_path) }
     it { should_not have_link('Sign in', href: signin_path) }
     end

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

describe "Authentication" do
.
.
.
.
  describe "with valid information" do
    let(:user) { FactoryGirl.create(:user) }
    before do
      fill_in "Email",    with: user.email.upcase
      fill_in "Password", with: user.password
      click_button "Sign in"


    #it { should have_title(user.name) }
    #it { should have_selector('title', text: user.name) }
    it { should have_selector( "title", :content => user.name)}
    it { should have_link('Profile',     href: user_path(user)) }
    it { should have_link('Sign out',    href: signout_path) }
    it { should_not have_link('Sign in', href: signin_path) }
  end

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

<header class="navbar navbar-fixed-top navbar-inverse">
  <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) Authentication signin with valid information followed by signout 
   Failure/Error: it { should have_selector( "title", :content => user.name)}
   NoMethodError:
   undefined method `it' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_2::Nested_2::Nested_1:0xb4063c4>
 # ./spec/requests/authentication_pages_spec.rb:42:in `block (4 levels) in <top (required)>'

这里怎么了?我的语法是正确的,这行之前没有给出错误,为什么现在呢?如果您能提供任何帮助和解释,我们将不胜感激。

您尚未登录。检查失败的
descripe
子句上的嵌套/缩进,您会发现您终止了“with valid information”在
it
一行程序之后立即使用
end
提前阻塞。

嘿,感谢您的帮助,修复了错误。但是,当我再次运行rspec时,我遇到了一个新错误。具有有效信息并后跟注销失败/错误的身份验证登录:它{应该有_选择器(“title”,:content=>user.name)}NoMethodError:未定义的方法“it”。关于如何解决这个问题有什么帮助吗?感谢“it”仅在“descripe”块中定义给我错误的it代码在descripe块中,但我仍然得到错误,我很困惑,请查看身份验证页面规范的修改版本。现在
it
位于
之前的
块中。你以前住的街区很好。正如我所说,前面的问题是
descripe
块的过早终止。您需要将上一个
description
之前的
end
移到后面。如果您确保缩进总是正确的,这些问题就不太可能“咬住”您。
1) Authentication signin with valid information followed by signout 
   Failure/Error: it { should have_selector( "title", :content => user.name)}
   NoMethodError:
   undefined method `it' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_2::Nested_2::Nested_1:0xb4063c4>
 # ./spec/requests/authentication_pages_spec.rb:42:in `block (4 levels) in <top (required)>'
require 'spec_helper'

describe "Authentication" do
.
.
.
.
  describe "with valid information" do
    let(:user) { FactoryGirl.create(:user) }
    before do
      fill_in "Email",    with: user.email.upcase
      fill_in "Password", with: user.password
      click_button "Sign in"


    #it { should have_title(user.name) }
    #it { should have_selector('title', text: user.name) }
    it { should have_selector( "title", :content => user.name)}
    it { should have_link('Profile',     href: user_path(user)) }
    it { should have_link('Sign out',    href: signout_path) }
    it { should_not have_link('Sign in', href: signin_path) }
  end

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