我正在阅读 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)>'
这是我的测试文件:
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
这是我的 new.html.erb 文件:
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<p>Find me in app/views/users/new.html.erb</p>
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
应用程序.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>
我不确定我做错了什么。让我知道我是否应该提供更多信息。
谢谢。