stub_chain together with should_receive

后端 未结 1 705
日久生厌
日久生厌 2021-02-07 15:19

I am trying to test if in a method calling chain one of the methods get a specific parameter. In the below code for example MyModel must receive the parameter 0 for the method <

相关标签:
1条回答
  • 2021-02-07 16:13

    This is an example what I do in one of my specs now. It's a bit unhandy (cause of the many lines), but it works:

    SearchPaginationModel.stub(:tag_counts) { SearchPaginationModel }
    SearchPaginationModel.should_receive(:offset).with(0) { SearchPaginationModel }
    SearchPaginationModel.stub_chain(:limit, :where, :order) { [] }
    SearchPaginationModel.stub_chain(:tag_counts, :where, :count).and_return(1)
    SearchPaginationModel.search_tags(:page => "1")
    

    This for example tests in SearchPaginationModel.tag_counts.offset(0).limit(X).where(X).order(X) that really offset 0 is set.

    0 讨论(0)
提交回复
热议问题