Rails教程预期的带有文本的css标题可返回某些内容 [英] rails tutorial expected css title with text to return something
问题描述
我正在浏览ruby.railstutorial.org上的RoR教程,当前正在第4章上进行。测试未通过验证,我也不知道为什么。
我的规格文件的顶部看起来像这样。所有其他方法看上去都与帮助相同:
I am working through the RoR tutorial at ruby.railstutorial.org and am currently on chapter 4. The tests aren't validating and I have no idea why. Top part of my spec file looks like this. The other methods all look identical to Help:
describe "StaticPages" do
let(:page_title) {"Ruby on Rails Tutorial Sample App"}
let(:h1_test) {"should have the h1"}
let(:title_test) {"should have the title"}
describe "Home page" do |title_test, h1_test|
it "#{h1_test} 'Sample App'" do
visit '/static_pages/home'
page.should have_selector('h1',:text=>'Sample App')
end
it "#{title_test} 'Home'" do
visit '/static_pages/home'
page.should have_selector('title', :text=> '#{page_title}')
end
it "should not have a custom page title" do
visit '/static_pages/home'
page.should_not have_selector('title', :text=> '| Home')
end
end
describe "Help page" do |title_test, h1_test|
it "#{h1_test} 'Help'" do
visit '/static_pages/help'
page.should have_selector('h1', :text =>'Help')
end
it "#{title_test} 'Help'" do
visit '/static_pages/help'
page.should have_selector('title',
:text=>'#{page_title} | Help')
end
end
我的application_helper.rb:
My application_helper.rb:
module ApplicationHelper
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.haml文件:
My application.html.haml file:
!!!
%html
%head
%title= full_title(yield(:title))
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
%body= yield
现在4个错误是相同的,减去一个单词更改,所以我只发布一个:
Now the 4 errors are identical minus one word change, so I'll just post one:
1) StaticPages Contact#<Class:0x0000000446e818> 'Contact'
Failure/Error: page.should have_selector('title', :text=>'#{page_title} | Contact')
expected css "title" with text "\#{page_title} | Contact" to return something
# ./spec/requests/static_pages_spec.rb:65:in `block (3 levels) in <top (required)>'
我很迷惑,因为我只是直接从指南中复制它,而不是使用haml并将规范文件中的前几行添加到最小化重复文本。我没有包含页面html文件,因为我看不到它们可能是什么问题。尤其是由于home.html.haml像其他的一样没有-offer(:title,'Home')
,但仍会引发与上述相同的错误。
任何帮助将不胜感激!
I am mystified because I am just copying it straight from the guide other than using haml and adding in those top few lines in my spec file to minimize repeat text. I didn't include the page html files because I can't see how they could be the problem. Especially since the home.html.haml doesn't have a - provide(:title, 'Home')
like the others but is still throwing the same error as above.
Any help would be greatly appreciated!
编辑:这是我的Gemfile:
Here is my Gemfile:
gem 'rails', '3.2.12'
gem 'haml', '4.0.0'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
gem 'haml-rails', '0.4'
gem 'guard-rspec', '1.2.1'
gem 'guard-spork', '1.4.2'
gem 'spork', '0.9.2'
end
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails','3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.2'
group :test do
gem 'capybara', '1.1.2'
gem 'rb-inotify', '0.8.8'
gem 'libnotify', '0.5.9'
end
group :production do
gem 'pg', '0.12.2'
end
推荐答案
问题。在我说‘#{page_title}’
的地方,应该是#{page_title}
。双引号而不是单引号-_-。有人可以告诉我为什么吗?尤其是因为我在相同的have_selector检查中包含了示例应用
之类的东西,因此不会引发任何错误。希望这至少对将来的人有帮助。
I figured out the problem. Where I say '#{page_title}'
it should be "#{page_title}"
. Double quotes instead of single quotes -_-. Can someone tell me why that works? Especially because I have stuff like 'Sample App'
in the same have_selector checks and that doesn't throw any kind of error. Hope this helps someone in the future at least.
这篇关于Rails教程预期的带有文本的css标题可返回某些内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!