Я работаю над учебником Майкла Хартла Ruby on Rails, и я занимаюсь упражнениями главы 5. Может кто-нибудь объяснить, почему этот тест не работает?RoR Статические страницы Страницы справки должны иметь заголовок «Справка»
Мой routes.rb
SampleApp::Application.routes.draw do
root 'static_pages#home'
match '/help', to: 'static_pages#help', via: 'get'
match '/about', to: 'static_pages#about', via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get
end
Мой static_pages_spec.rb
require 'spec_helper'
describe "Static pages" do
let(:base_title) { "Ruby on Rails Tutorial Sample App" }
describe "Home page" do
it "should have the h1 'Sample App'" do
visit root_path
expect(page).to have_content('Sample App')
end
it "should have the base title" do
visit root_path
expect(page).to have_title("Ruby on Rails Tutorial Sample App")
end
it "should not have a custom page title" do
visit root_path
expect(page).not_to have_title('| Home')
end
end
describe "Help page" do
it "should have the h1 'Help'" do
visit help_path
expect(page).to have_content('Help')
end
it "should have the title 'Help'" do
visit help_path
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help")
end
end
describe "About page" do
it "should have the h1 'About Us'" do
visit about_path
expect(page).to have_content('About Us')
end
it "should have the title 'About Us'" do
visit about_path
expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us")
end
end
describe "Contact page" do
it "should have the content 'Contact'" do
visit contact_path
expect(page).to have_content('Contact')
end
it "should have the title 'Contact'" do
visit contact_path
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Contact")
end
end
end
Мой тест: gvyntyk @ gvyntyk-r60: ~/rails_projects/sample_app $ RSpec спецификации/запросы/static_pages_spec.rb .... F ... F
Failures:
1) Static pages Help page should have the title 'Help'
Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help")
expected #has_title?("Ruby on Rails Tutorial Sample App | Help") to return true, got false
# ./spec/requests/static_pages_spec.rb:34:in `block (3 levels) in <top (required)>'
2) Static pages About page should have the title 'About Us'
Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us")
expected #has_title?("Ruby on Rails Tutorial Sample App | About Us") to return true, got false
# ./spec/requests/static_pages_spec.rb:47:in `block (3 levels) in <top (required)>'
Finished in 0.67805 seconds
9 examples, 2 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:32 # Static pages Help page should have the title 'Help'
rspec ./spec/requests/static_pages_spec.rb:45 # Static pages About page should have the title 'About Us'
Хотя веб-приложение ж orks, я могу открыть/о странице и/помочь.
[email protected]:~/rails_projects/sample_app$ rails server
=> Booting WEBrick
=> Rails 4.0.2 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-01-25 20:01:19] INFO WEBrick 1.3.1
[2015-01-25 20:01:20] INFO ruby 2.0.0 (2014-11-13) [i686-linux]
[2015-01-25 20:01:20] INFO WEBrick::HTTPServer#start: pid=17314 port=3000
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2015-01-25 20:01:29 +0200
Started GET "/assets/rails.png" for 127.0.0.1 at 2015-01-25 20:01:31 +0200
Started GET "/help" for 127.0.0.1 at 2015-01-25 20:01:42 +0200
Processing by StaticPagesController#help as HTML
Rendered static_pages/help.html.erb within layouts/application (2.9ms)
Rendered layouts/_shim.html.erb (0.8ms)
Rendered layouts/_header.html.erb (1.8ms)
Rendered layouts/_footer.html.erb (1.4ms)
Completed 200 OK in 516ms (Views: 513.2ms | ActiveRecord: 0.0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2015-01-25 20:01:43 +0200
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2015-01-25 20:01:43 +0200
Started GET "/assets/static_pages.css?body=1" for 127.0.0.1 at 2015-01-25 20:01:43 +0200
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2015-01-25 20:01:43 +0200
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2015-01-25 20:01:43 +0200
Started GET "/assets/static_pages.js?body=1" for 127.0.0.1 at 2015-01-25 20:01:43 +0200
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2015-01-25 20:01:43 +0200
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2015-01-25 20:01:43 +0200
Started GET "/about" for 127.0.0.1 at 2015-01-25 20:01:51 +0200
Processing by StaticPagesController#about as HTML
Rendered static_pages/about.html.erb within layouts/application (0.9ms)
Rendered layouts/_shim.html.erb (0.2ms)
Rendered layouts/_header.html.erb (2.9ms)
Rendered layouts/_footer.html.erb (0.4ms)
Completed 200 OK in 56ms (Views: 55.2ms | ActiveRecord: 0.0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2015-01-25 20:01:51 +0200
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2015-01-25 20:01:51 +0200
Started GET "/assets/static_pages.css?body=1" for 127.0.0.1 at 2015-01-25 20:01:51 +0200
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2015-01-25 20:01:51 +0200
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2015-01-25 20:01:51 +0200
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2015-01-25 20:01:51 +0200
Started GET "/assets/static_pages.js?body=1" for 127.0.0.1 at 2015-01-25 20:01:51 +0200
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2015-01-25 20:01:51 +0200
^C[2015-01-25 20:02:34] INFO going to shutdown ...
[2015-01-25 20:02:34] INFO WEBrick::HTTPServer#start done.
Exiting
Без кода просмотра мы не можем видеть, действительно ли вы находитесь на этой странице. Попробуйте также посмотреть консоль сервера, чтобы узнать, есть ли ошибка 302. – alkuzad
. Я не получаю ошибку 302, я добавил сервер журнала, и я могу открыть/о странице и/помочь. Но я не уверен, что он работает правильно и после этого проходит тест. – Gvyntyk
Может ли это быть потому, что ваш заголовок фактически не установлен в представлении? – benjaminjosephw