I am working through the Ruby on Rails Tutorial by Michael Hartl and I keep getting a failing test that I cannot figure out.
我正在学习Michael Hartl的Ruby on Rails教程,我一直在做一个我无法理解的失败测试。
Here is the failure I am getting:
下面是我遇到的失败:
User pages signup page:
用户页面注册页面:
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)>'
Here is my test file:
这是我的测试文件:
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
Here is my new.html.erb file:
这是我的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:
:引入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
application.html.erb:
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>
I am not sure what I am doing wrong. Let me know if I should provide more information.
我不知道我做错了什么。如果我需要提供更多的信息,请告诉我。
Thanks.
谢谢。
2 个解决方案
#1
7
Your test is expecting "Sign up", you're passing "Sign Up". Note the difference in capitalization on the word "up".
你的考试在期待“注册”,你在通过“注册”。注意“up”这个词的大小写差异。
#2
0
Can you post your Application Layout file (/app/views/layouts/application.erb.html
) file?
你能发布你的应用程序布局文件(/应用程序/视图/布局/应用程序。erb.html)吗?
I'm not sure, but it looks as if you may be providing content for the :title
yield section of that file -- and potentially where that is being substituted into the application layout file may not be what you think.
我不确定,但看起来您可能正在为该文件的:title yield部分提供内容——而且可能在应用程序布局文件中替换的内容与您所想的不一样。
That is, in the application.erb.html
file it looks as if you've for a section yield :title
-- but it may not be rendering as your test thinks it should be.
也就是说,在应用程序中。html文件看起来就像您已经获得了section yield:title——但是它可能不会像您的测试认为的那样呈现出来。
Can you edit your question and add the application layout (or at least the appropriate section)?
您可以编辑您的问题并添加应用程序布局(或者至少是适当的部分)吗?
#1
7
Your test is expecting "Sign up", you're passing "Sign Up". Note the difference in capitalization on the word "up".
你的考试在期待“注册”,你在通过“注册”。注意“up”这个词的大小写差异。
#2
0
Can you post your Application Layout file (/app/views/layouts/application.erb.html
) file?
你能发布你的应用程序布局文件(/应用程序/视图/布局/应用程序。erb.html)吗?
I'm not sure, but it looks as if you may be providing content for the :title
yield section of that file -- and potentially where that is being substituted into the application layout file may not be what you think.
我不确定,但看起来您可能正在为该文件的:title yield部分提供内容——而且可能在应用程序布局文件中替换的内容与您所想的不一样。
That is, in the application.erb.html
file it looks as if you've for a section yield :title
-- but it may not be rendering as your test thinks it should be.
也就是说,在应用程序中。html文件看起来就像您已经获得了section yield:title——但是它可能不会像您的测试认为的那样呈现出来。
Can you edit your question and add the application layout (or at least the appropriate section)?
您可以编辑您的问题并添加应用程序布局(或者至少是适当的部分)吗?