【发布时间】:2010-12-24 11:45:53
【问题描述】:
我想测试这个销毁动作:
def destroy
@comment = Comment.find(params[:id])
@comment_id = @comment.id
if @comment.delete_permission(current_user.id)
@remove_comment = true
@comment.destroy
else
@remove_comment = false
head :forbidden
end
end
我的规格是这样的:
describe "DELETE 'destroy'" do
describe 'via ajx' do
it "should be successful if permission true" do
comment = Comment.stub(:find).with(37).and_return @comment
comment.should_receive(:delete_permission).with(@user.id).and_return true
comment.should_receive(:destroy)
delete 'destroy', :id => 37
end
end
end
我总是得到:
comment.should_receive....
expected: 1 time
received: 0 times
为什么 :delete_permission 永远不会被调用?您对如何测试它有什么建议吗?
【问题讨论】:
-
我以为comment = Comment.stub(:find).with(37).and_return @comment 会将@comment 分配给评论。谢谢