わかりましたので、すべてのページに特定のタイトルがあることを確認するためのテストを作成したいと思います。array
ただし、各ページのブロックを複製する必要がないように、ページ タイトルを に含めることができればいいと思いました。を変更するだけで、追加のページをテストできますpages array
。
私が抱えている問題は、ページ変数がテストで補間されていないことです。これは構文エラーですか、それとも Rspec はit should do...
ブロック内での補間を許可していませんか?
describe "LayoutLinks" do
page = ["home", "contact", "about", "help"]
i = page.count
x = 0
while x < i
it "should have a #{page[x]} page" do
get "#{page[x]}"
response.should have_selector("title", :content => "#{page[x]}")
end
x += 1
end
end
テストでは、次のエラーが表示されます。
1) PagesController LayoutLinks should have a help page
Failure/Error: get "#{page[x]}"
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>""}
# ./spec/controllers/layout_links_spec.rb:14:in `block (3 levels) in <top (required)>'
2) PagesController LayoutLinks should have a contact page
Failure/Error: get "#{page[x]}"
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>""}
# ./spec/controllers/layout_links_spec.rb:14:in `block (3 levels) in <top (required)>'
3) PagesController LayoutLinks should have a about page
Failure/Error: get "#{page[x]}"
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>""}
# ./spec/controllers/layout_links_spec.rb:14:in `block (3 levels) in <top (required)>'
4) PagesController LayoutLinks should have a home page
Failure/Error: get "#{page[x]}"
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>""}
ここでの失敗エラーは明らかです。get と言うべきではなく、 andなど"#{page[x]}"
とすべきです...get home
get about
どうすれば治りますか?助けてくれてありがとう。とても有難い :)