문제

여기 루비 초보자.나는 레일 튜토리얼을 따르고 있으며 5.3 Re : routes 약 5.3 회.

에는 유사한 테스트 세트가있는 모든 것들이 5 페이지 (가정, 정보, 도움말, 연락처)를 모두 가지고 있으며, RSPEC은 '홈'의 테스트가 실패합니다.Application_helper를 사용하고 있으므로 home.html.erb에서 지정할 필요가 없어야합니다.나는 또한 Rails Routes 이해 : VS 루트와 일치하는routes.rb 및 "일치"/ static_pages / home '=>'static_pages # home 'to routes.db.

이 2 가지 오류를 잠시 멈추었습니다.도와주세요.감사합니다!

오류 :

1) Static pages Home page should have the h1 'Sample App'
Failure/Error: page.should have_selector('h1', text: 'Sample App')
expected css "h1" with text "Sample App" to return something
# ./spec/requests/static_pages_spec.rb:9:in `block (3 levels) in <top (required)>'

2) Static pages Home page should have the base title
Failure/Error: page.should have_selector('title',
expected css "title" with text "Ruby on Rails Tutorial Sample App" to return something
# ./spec/requests/static_pages_spec.rb:13:in `block (3 levels) in <top (required)>'
.

home.html.erb

<div class="center hero-unit">
<h1>Welcome to the Sample App</h1>

<h2>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</h2>

<%= link_to "Sign up now!", '#', class: "btn btn-large btn-primary" %>
</div>

<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>
.

static_pages_spec.rb

require 'spec_helper'

describe "Static pages" do

  describe "Home page" do

  it "should have the h1 'Sample App'" do
    visit root_path
    page.should have_selector('h1', text: 'Sample App')
  end

  it "should have the base title" do
    visit root_path
    page.should have_selector('title', text: "Ruby on Rails Tutorial Sample App")
  end

  it "should not have a custom page title" do
    visit root_path
    page.should_not have_selector('title', text: '| Home')
  end
end
.

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

application_helper.rb

module ApplicationHelper

# Returns the full title on a per-page basis.
def full_title (page_title)
    base_title = "Ruby on Rails Tutorial Sample App"
    if page_title.empty?
        base_title
    else
        "#{base_title} | #{page_title}"
    end
end

end
.

routes.rb

SampleApp::Application.routes.draw do
  match '/help',    to: 'static_pages#help'
  match '/about',   to: 'static_pages#about'
  match '/contact', to: 'static_pages#contact' 
  match '/static_pages/home' => 'static_pages#home'

  root to: 'static_pages#home'
end
.

다른 것이 필요한지 알려주세요.감사합니다!

도움이 되었습니까?

해결책

는 브라우저에서 /에서 또는 예상 템플릿을 렌더링 할 수 있음을 시각적으로 확인하고 시각적으로 확인했습니다.귀하의 사양은 그렇지 않으면 괜찮아 보입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top