通过浏览控制器测试教程,作者给出了一个rspec测试控制器动作的示例.我的问题是,为什么他们使用attributes_for
比build
的方法?除了返回一个散列值之外,没有明确的解释为什么使用attributes_for
.
it "redirects to the home page upon save" do
post :create, contact: Factory.attributes_for(:contact)
response.should redirect_to root_url
end
教程链接可在此处找到:http://everydayrails.com/2012/04/07/testing-series-rspec-controllers.html示例可在开始主题第Controller testing basics
节找到