0

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>
4

1 に答える 1