How to say “any_instance” “should_receive” any number of times in RSpec

后端 未结 7 1916
刺人心
刺人心 2020-12-14 05:24

I\'ve got an import controller in rails that imports several csv files with multiple records into my database. I would like to test in RSpec if the records are actually save

7条回答
  •  星月不相逢
    2020-12-14 06:04

    You may try to count the number of new on the class. That is not actually tests the number of saves but may be enough

        expect(Mutation).to receive(:new).at_least(:once)
    

    If there is the only expectation of how many times it was saved. Then you probably want to use spy() instead of fully functioning factory, as in Harm de Wit own answer

        allow(Mutation).to receive(:new).and_return(spy)
        ...
        expect(Mutation.new).to have_received(:save).at_least(:once)
    

提交回复
热议问题