Pla*_*Ton 7 rspec ruby-on-rails mocking stub
我刚刚开始使用RSpec,并且在编写嵌套资源的控制器测试时遇到一些困难.我试过谷歌搜索,但没有太多运气.
有人可以提供"PUT更新"测试测试的基本示例,以确保更新嵌套资源吗?只是详细说明,我有像这样测试的等效(非嵌套)资源:
def mock_post(stubs={})
@mock_post ||= mock_model(Post, stubs).as_null_object
end
...
describe "PUT update" do
describe "with valid parameters" do
it "updates the requested post" do
Post.stub(:find).with("14") { mock_post }
mock_post.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => "14", :post => {'these' => 'params'}
end
end
end
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一段时间来正确地对一个嵌套在Post下的"Comment"模型进行类似测试,但没有任何乐趣.任何建议赞赏.
mon*_*cle 12
您需要将两个id传递给put方法
put :update, :id => "14", :post_id=> "1", :comment => {'these' => 'params'}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3358 次 |
| 最近记录: |