【发布时间】:2014-05-21 18:39:25
【问题描述】:
我是 Ruby on rails 的新手。目前使用 maverick 的 10.9.3,Rails 4。当我尝试运行 rspec 命令时出现以下错误。
这是我得到的错误:
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
我的 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
也是我的 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
来自以下评论的控制器代码:
class PagesController < ApplicationController
def home
end
def contact
end
def about
end
end
【问题讨论】:
-
Michael 的教程是有史以来最有效的 :) 无论如何.. 我发现另外一件非常有用的事情是
gem launchy。得到它,你可以在visit之后调用save_and_open_page来查看页面的样子。 -
实际控制器代码如下: class PagesController
-
Ruby On rails Tutorial sample App |关于 关于
这是主页
Ruby on rails教程 示例应用。 -
请使用控制器代码编辑问题,使其更具可读性。
标签: ruby-on-rails ruby rspec