【发布时间】:2013-09-01 21:02:43
【问题描述】:
好的,所以我想创建一个测试来检查所有页面是否都有特定的标题。但是我认为如果我可以在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=>""}
这里的失败错误很明显。它不应该说得到"#{page[x]}",而应该是get home 和get about,等等......
我该如何补救?谢谢您的帮助。非常感谢:)
【问题讨论】:
标签: ruby-on-rails rspec tdd