Отказ испытаний RSPEC: статические страницы о странице должны иметь название «О нас» Hartl CH.3.
-
11-12-2019 - |
Вопрос
Я работаю через Рубиновые рубрики Майкла Хартла на рельсы Учебник, и я делаю упражнения в главе 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
.
Маршруты.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