[英]Michael Hartl's rails tutorial chapter 3, Error in rspec when
I am newbie to Ruby on rails. 我是Ruby的新手。 currently using maverick's 10.9.3, Rails 4. I am getting the following error when I try to run the rspec command. 当前使用特立独行的10.9.3,Rails4。尝试运行rspec命令时出现以下错误。
here is the error that i get: 这是我得到的错误:
rspec ./spec/controllers/pages_controller_spec.rb:35 # PagesController GET 'about' should have the right title
rspec ./spec/controllers/pages_controller_spec.rb:24 # PagesController GET 'contact' should have the right title
rspec ./spec/controllers/pages_controller_spec.rb:11 # PagesController GET 'home' should have the right title
my Gemfile includes: 我的Gemfile包括:
group :development, :test do
gem 'rspec-rails', '2.14.2'
end
group :test do
gem 'rspec', '2.14.1'
gem 'spork', '0.9.0.rc'
end
also my pages_controller_spec.rb 还有我的pages_controller_spec.rb
require 'spec_helper'
describe PagesController do
render_views
describe "GET 'home'" do
it "returns http success" do
get 'home'
response.should be_success
end
it "should have the right title" do
get 'home'
response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Home")
end
end
describe "GET 'contact'" do
it "returns http success" do
get 'contact'
response.should be_success
end
it "should have the right title" do
get 'contact'
response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Contact")
end
end
describe "GET 'about'" do
it "returns http success" do
get 'about'
response.should be_success
end
it "should have the right title" do
get 'about'
response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | About")
end
end
end
Controller code from the comment below: 控制器代码来自以下注释:
class PagesController < ApplicationController
def home
end
def contact
end
def about
end
end
您是否尝试过检查文档: https : //relishapp.com/rspec
Is it as simple as a lower case "a" for about vs About? 它与About和About的小写字母“ a”一样简单吗?
Your test is looking for the string "Ruby on Rails Tutorial Sample App | About" and the code is producing "Ruby on Rails Tutorial Sample App | about". 您的测试正在寻找字符串“ Ruby on Rails教程示例应用程序|关于”,而代码正在生成“ Ruby on Rails教程示例应用程序|关于”。 As far as I know, rspec is case sensitive. 据我所知,rspec是区分大小写的。
The other thing I have seen is having to set :visible to false for testing titles. 我看到的另一件事是必须将:visible设置为false以测试标题。
You may also come across this mistake Ruby on Rail Michael Hartl's Chapter 3 Error . 您可能还会遇到这个错误Ruby on Rail Michael Hartl的Chapter 3 Error 。 You may be having this error as caught by the built-in test suite of Rails (which at the time of this writing is 'rails-controller-testing' - '1.0.2', 'minitest' - '5.10.3', 'minitest-reporters' - '1.1.14') 您可能会因为内置的Rails测试套件(在撰写本文时为'rails-controller-testing'-'1.0.2','minitest'-'5.10.3', 'minitest-reporters'-'1.1.14')
I advise you follow Michael Hartl's Gemfiles when reading his book to learn Rails. 我建议您在阅读Michael Hartl的书以学习Rails时遵循其Gemfiles。
provide
stores a block of markup in an identifier for later use.provide
将标记块存储在标识符中,以备后用。 In this case, 'Help' in the symbol :title. 在这种情况下,请在符号:title中使用“帮助”。 The provide is enclosed in<% %>
to indicate it is executing this code and not printing out in the view. 提供包含在<% %>
以指示它正在执行此代码且未在视图中打印出来。
yield
in this case just spits that block back out. 在这种情况下,yield
只是吐出而被阻止。 The yield is enclosed in<%= %>
to indicate it is being printed out into the view. 产量包含在<%= %>
以指示它已被打印到视图中。Think of it as setting a variable and printing out a variable. 将其视为设置变量并打印出变量。
See: http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#method-i-provide for more information. 有关更多信息,请参见: http : //api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#method-i-provide 。 Note that provide is really a wrapper for content_for so that's where the good stuff is in that link. 请注意,provide实际上是content_for的包装,因此,该链接中的好地方就在这里。
This is taken from this StackOverflow article: yield and provide() inside template 这摘自以下StackOverflow文章: 模板中的yield和 Provide ()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.