测试 feature 测试针对 #index 页面非女汉子的写法

leopku · November 04, 2013 · Last by xdite replied at November 05, 2013 · 3787 hits

标准的#index 页面,列出记录集

let!(:photos_list) { FactoryGirl.create_list(:photo, 3) }

visit photos_path

photos_list.each do |photo|
  expect(page).to have_content photo.name
end

感觉太女汉子了,求温柔点的写法

#1 楼 @nightire 太感谢了,不仅解答了我的问题,还额外做了很多说明。

@nightire 每次总能看到你精彩的回复,我这里搜测试相关的资料,都能看到你的长回复 👍 最近努力的 TDD……

@nightire 请问一下,最近看到很多人转向用https://github.com/paulelliott/fabrication ,不知这东西和 FactoryGirl 相比,有什么明显的优势?谢谢

http://stackoverflow.com/questions/12179107/comparing-factory-girl-with-fabrication

Fabrication 的好處是生物件不會 hit db ...Factory.build_stubbed 還不一定....

#5 楼 @xdite 最近在上@knwang 的课,里面用的是 Fabrication,他也说他在自己的项目中也是使用这个。因为自己也读了https://leanpub.com/everydayrailsrspec-cn 用的是 FactoryGirl,写法上都差不多,所以一直都用 FactoryGirl。感觉会不会 Fabrication 更加轻量,并对多种数据库支持更好一些呢。

You need to Sign in before reply, if you don't have an account, please Sign up first.