0

私はMichael Hartlのチュートリアルに従っていますが、何らかの理由でテスト時にこのエラーが発生しているようです:

Failures:   

1) PagesController GET 'home' should have the right title
 Failure/Error: response.should have_selector("title",
   expected css "title" to return something
 # ./spec/controllers/pages_controller_spec.rb:18:in `block (3 levels) in <top (required)>'

Finished in 0.11535 seconds
4 examples, 1 failure

Failed examples:

rspec ./spec/controllers/pages_controller_spec.rb:16 # PagesController GET 'home' should have the right title

Randomized with seed 19403

ここに私の pages_controller_spec ファイルの内容があります:

require 'spec_helper'



describe PagesController do


render_views

describe "GET 'home'" do
it "returns http success" do
  get 'home'
  response.should be_success
end

it "should have the right title" do
  get 'home'
  response.should have_selector("title", 
      :content => "Ruby on rails tutorial sample app | Home")
 end
 end

describe "GET 'contact'" do
it "returns http success" do
  get 'contact'
  response.should be_success
 end
end


describe "GET 'about'" do
it "returns http success" do
  get 'about'
  response.should be_success
end
 end
 end

そして、ここに私の home.html.erb ファイルの内容があります:

<!DOCTYPE>
<html>
<head>
    <title>Ruby on rails tutorial sample app | Home</title>
</head>
<body>
    <h1>Pages#home</h1>
    <p>Find me in app/views/pages/home.html.erb</p>
</body>
 </html>
4

1 に答える 1

1

ええ、それは私にも起こりました。チュートリアルに記載されている正確なバージョンのカピバラを使用していることを確認してください。すなわち 1.1.2

多くのバリエーションや代替案を試しましたが、最新のカピバラにはまだ互換性の問題があるという結論に達しました。

お役に立てれば。

更新:それを釘付けにしました。ブラウザからホームページのソースをチェックアウトします。アプリケーションのレイアウトはyield inside を使用するため<body>、home.html.erb のすべての html は実際には body 内で置き換えられ ( タグ<title>内でその部分が置き換えられていても)、効果的に要素<body>を無効<head>にします。<title>そのため、ビュー固有のタイトルはまだありません。/views/layout/application.html.erb で定義されたタイトルがホームページで使用されています。

私のアドバイスは、チュートリアルを進めることです。ほんの数ステップで、テストに合格できます。

于 2013-02-02T05:29:27.130 に答える