好的,所以我想创建一个测试来检查所有页面是否都有特定的标题。但是,我认为如果我可以将页面标题包含在一个中会很好,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"#{page[x]}"
而是应该是get home
andget about
等等......
我该如何补救?谢谢您的帮助。非常感激 :)