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

后端 未结 7 1927
刺人心
刺人心 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 05:52

    I finally managed to make a test that works for me:

      mutation = FactoryGirl.build(:mutation)
      Mutation.stub(:new).and_return(mutation)
      mutation.should_receive(:save).at_least(:once)
    

    The stub method returns one single instance that receives the save method multiple times. Because it is a single instance i can drop the any_instance method and use the at_least method normally.

提交回复
热议问题