私はウェブとStackOverflowを調べて、これらのテストを機能させる方法を見つけてきました。私はRuby&Railsを初めて使用するので、Hartlのチュートリアルに従っています。ほとんどのコードをコピーして貼り付け、最終的にすべてがどのようにまとめられるかを確認してください。
今、私はセクション3.3「やや動的なページ」で立ち往生しています。
これは私が受け取っているエラーです:
C:\Sites\sample_app>bundle exec rspec --no-color spec/requests/static_pages_spec.rb
F.F.F.
Failures:
1) Static pages About page should have the title 'About Us'
Failure/Error: page.should have_selector('title',
expected css "title" with text "Ruby on Rails Tutorial Sample App | About Us" to return something
# ./spec/requests/static_pages_spec.rb:44:in `block (3 levels) in <top (required)>'
2) Static pages Help page should have the title 'Help'
Failure/Error: page.should have_selector('title',
expected css "title" with text "Ruby on Rails Tutorial Sample App | Help" to return something
# ./spec/requests/static_pages_spec.rb:29:in `block (3 levels) in <top (required)>'
3) Static pages Home page should have the title 'Home'
Failure/Error: page.should have_selector('title',
expected css "title" with text "Ruby on Rails Tutorial Sample App | Home" to return something
# ./spec/requests/static_pages_spec.rb:14:in `block (3 levels) in <top (required)>'
Finished in 3.09 seconds
6 examples, 3 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:42 # Static pages About page should have the title 'About Us'
rspec ./spec/requests/static_pages_spec.rb:27 # Static pages Help page should have the title 'Help'
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the title 'Home'
Randomized with seed 25648
このHTML構造(About / Home / Help.html.erbファイル内)から切り替えるとすぐにエラーが発生します。
<% provide(:title, 'Home') %>
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title>
</head>
<body>
<h1>Sample App</h1>
<p>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</p>
</body>
</html>
これに:
<% provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</p>
その他の関連ファイル:
Application.html.erb:
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
static_pages_spec.rb
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the h1 'Sample App'" do
visit '/static_pages/home'
page.should have_selector('h1', :text => 'Sample App')
end
it "should have the title 'Home'" do
visit '/static_pages/home'
page.should have_selector('title',
:text => "Ruby on Rails Tutorial Sample App | Home")
// The line below is something I tried replacing the page.should have_selector with
// page.should have_xpath("//title", :text => "Home")
end
end
.... (other describe pages, same structure)
end
Hartlのチュートリアルからコピー/貼り付け/読み取りの過程で盲目になったかもしれませんが、彼が説明したのと同じように見えることはかなり気になります。
私はこれに対する解決策を探すために最善を尽くしましたが、残念ながら私はそれを理解することができなかったので、ここに行きます!
乾杯!
編集:フィオナ#1への回答
このURL: "http:// localhost:3000 / static_pages / home"
ドキュメントのタイトルは何もありません。
ドキュメントのソースは次のようになります。
<h1>Sample App</h1>
<p>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</p>
ソースには、Doctype、head、body、またはtitleの宣言はありません。