2013-06-28 2 views
0

Im просматривает учебник Ruby on Rails Майкла Хартла и столкнулся с этой проблемой. Вместо обычной ошибки rspec, чтобы вернуть что-то, я получил следующую ошибку.Ожидается, что css «title» с текстом «Помощь» не вернет ничего

статических страниц, страница Помощь

Failure/Error: it { should_not have_selector 'title', text: "| Help" } 
    expected css "title" with text "| Help" not to return anything 
# ./spec/requests/static_pages_spec.rb:27:in `block (3 levels) in <top (required)>' 

Мой RSpec static_pages_spec.rb

require 'spec_helper' 

describe "Static pages" do 
    subject {page} 

    shared_examples_for "all static pages" do 
     it { should have_selector('h1', text: heading)} 
     it { should have_selector('title', text: full_title(page_title))} 
    end 

    describe "Home page" do 
     before { visit root_path } 
     let(:heading) {'Welcome to TechnoEdge'} 
     let(:page_title) {''} 

     it_should_behave_like "all static pages" 
     it { should_not have_selector 'title', text: '| Home' } 
    end 

    describe "Help page" do 
     before { visit help_path } 

     let(:heading) {'Help'} 
     let(:page_title) {'Help'} 

     it_should_behave_like "all static pages" 
     it { should_not have_selector 'title', text: "| Help" } 
    end 

    describe "About page" do 
     before { visit about_path } 

     let(:heading) {'About Us'} 
     let(:page_title) {'About Us'} 

     it_should_behave_like "all static pages" 
     it { should_not have_selector 'title', text: '| About us' } 
    end 


    describe "Contact page" do 
     before { visit contact_path } 

     let(:heading) {'Contact'} 
     let(:page_title) {'Contact'} 

     it_should_behave_like "all static pages" 
     it { should_not have_selector 'title', text: '| Contact page' } 
    end 
end 

home.html.erb

<% provide(:title, 'Help') %> 

<h1>Help</h1> 
<p>This is the Help page</p> 

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> 

ответ

0

Элемент TITLE должен находиться в ГОЛОВке документа.

+0

Я добавил application.html.erb. Название фактически находится в главной части документа –