预期css“标题”与文本“|帮助”不返回任何东西

时间:2013-06-28 17:13:40

标签: ruby-on-rails ruby rspec

我正在阅读Michael Hartl撰写的Ruby on Rails教程,并遇到了这个问题。而不是通常的rspec错误返回的东西,我得到以下错误。

静态页面,帮助页面

 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>

1 个答案:

答案 0 :(得分:0)

TITLE元素应出现在文档的HEAD中。