RSPEC 테스트 실패 : 페이지에 대한 정적 페이지는 'US에 관한 제목'의 제목이 있어야합니다. HARTL CH.삼
-
11-12-2019 - |
문제
나는 Rails 튜토리얼에서 마이클 하트의 루비를 통해 일하고 있으며, 나는 3 장 운동을하고 있습니다.이 테스트가 실패한 이유를 설명 할 수 있습니까?
나는 실패를 얻고있다
rspec ./spec/requests/static_pages_spec.rb:39 #
Static pages About page should have the title 'About Us'
.
컨트롤러
class StaticPagesController < ApplicationController
def home
end
def help
end
def about
end
def Contact
end
end
.
about.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails Tutorial Sample App | About Us</title>
</head>
<body>
<h1>About Us</h1>
.
spec.rb
describe "About page" do
it "should have the h1 'About Us'" do
visit '/static_pages/about'
page.should have_selector('h1', :text => 'About Us')
end
it "should have the title 'About Us'" do
visit '/static_pages/about'
page.should have_selector('title',
:text => "Ruby on Rails Tutorial Sample App | About Us")
end
end
.
routes.rb
SampleApp::Application.routes.draw do
get "static_pages/home"
get "static_pages/help"
get "static_pages/about"
get "static_pages/Contact"
end
. 해결책
시도
page.should have_xpath("//title", :text => "About Us")
. 다른 팁
Mhartl의 자습서를 따르고 GEM 'Capybara'를 사용하고 있다면 ': text=> ...'를 변경하십시오. ': Content=> ...'를 확인할 수 있습니다.통과하다. @Kuo Jimmy님께 감사드립니다.
제휴하지 않습니다 StackOverflow