有没有机会干掉Capybara代码?

时间:2011-07-15 13:50:33

标签: ruby-on-rails rspec capybara

# acceptance/users_spec.rb
page.should have_content 'Włosy'
page.should have_content 'Oczy'
page.should have_content 'Wzrost'
page.should have_content 'Waga'
page.should have_content 'Biust'
page.should have_content 'Biustonosz'
page.should have_content 'Talia'
page.should have_content 'Biodra'
page.should have_content 'Ubranie'
page.should have_content 'Obuwie'
page.should have_content 'Zakres pracy'
page.should have_content 'Preferowany region pracy'
page.should have_content 'Języki'
page.should have_content 'O sobie'
page.should have_content 'Twoja strona WWW'
page.should have_content 'Numer Gadu-Gadu'
page.should have_content 'Kursy, szkolenia'
page.should have_content 'Referencje'

我想知道我是否可以更好地使用此代码。我正在使用rspecsteak

1 个答案:

答案 0 :(得分:2)

你的测试可能有点过分 - 如果相同的代码生成了每个项目,你可以只测试其中的一个或两个以确保代码有效。

但除此之外,你可以这样做:

['Włosy', 'Oczy', .....].each { |item| page.should have_content(item) }