Я получаю три одинаковых типа ошибок при запуске Rspec.
Мой application_controller.rb - это:
<!DOCTYPE>
<html>
<head>
<title><%= @title %></title>
<%= csrf_meta_tag %>
</head>
<body>
<%= yield %>
</body>
</html>
My pages_controller_spec.rb - это:
require 'spec_helper'
describe PagesController do
render_views
describe "GET 'home'" do
it "should be successful" 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 | Home")
end
it "should have a non-blank body" do
get 'home'
response.body.should_not =~ /<body>\s*<\/body>/
end
end
describe "GET 'contact'" do
it "should be successful" 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 | Contact")
end
end
describe "GET 'about'" do
it "should be successful" 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 | About")
end
end
end
Моя ошибка:
7 examples, 3 failures
Failed examples:
rspec ./spec/controllers/pages_controller_spec.rb:12 # PagesController GET 'home' should have the right title
rspec ./spec/controllers/pages_controller_spec.rb:30 # PagesController GET 'contact' should have the right title
rspec ./spec/controllers/pages_controller_spec.rb:43 # PagesController GET 'about' should have the right title
My application.html.erb
<!DOCTYPE>
<html>
<head>
<title><%= @title %></title>
<%= csrf_meta_tag %>
</head>
<body>
<%= yield %>
</body>
</html>
Это мой вспомогательный файл:
module ApplicationHelper
# Return a title on a per-page basis.
def title
base_title = "Ruby on Rails Tutorial Sample App"
if @title.nil?
base_title
else
"#{base_title} | #{@title}"
end
end
end
А вот файл контроллера моих страниц:
class PagesController < ApplicationController
def home
@title = "Home"
end
def contact
@title = "Contact"
end
def about
@title = "About"
end
end
Мне не ясно, почему это не удается.