预期css"标题"与文本"Ruby on Rails Tutorial Sample App | Sign Up"返回一些内容

Log*_*ott 2 ruby rspec ruby-on-rails capybara railstutorial.org

我正在研究Michael Hartl的Ruby on Rails教程,并且我一直在进行一项我无法弄清楚的失败测试.

这是我得到的失败:

用户页面注册页面:

 Failure/Error: it { should have_selector('title', text: full_title('Sign Up')) }
 expected css "title" with text "Ruby on Rails Tutorial Sample App | Sign Up" to return something
 # ./spec/requests/user_pages_spec.rb:11:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

这是我的测试文件:

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
end
Run Code Online (Sandbox Code Playgroud)

这是我的new.html.erb文件:

<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<p>Find me in app/views/users/new.html.erb</p>
Run Code Online (Sandbox Code Playgroud)

application_helper.rb:

module ApplicationHelper

    # Returns the full title on a per-page basis.
    def full_title(page_title)
      base_title = 'Ruby on Rails Tutorial Sample App'
      if page_title.empty?
        base_title
      else
        "#{base_title} | #{page_title}"
      end
    end
end
Run Code Online (Sandbox Code Playgroud)

application.html.erb:

<!DOCTYPE html>
<html>
  <head>
    <title><%= full_title(yield(:title)) %></title>
    <%= stylesheet_link_tag    "application", media: "all" %>
    <%= javascript_include_tag "application" %>
    <%= csrf_meta_tags %>
    <%= render 'layouts/shim' %>
  </head>
    <body>
    <%= render 'layouts/header' %>
    <div class="container">
      <%= yield %>
      <%= render 'layouts/footer' %>
    </div>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我不确定我做错了什么.如果我应该提供更多信息,请告诉我.

谢谢.

The*_*Guy 7

您的测试期待"注册",您正在通过"注册".注意"up"这个词的大小写差异.