浏览有关控制器测试的教程,作者给出了一个 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