Rspec stubbing method for only specific arguments

前端 未结 2 1142
野的像风
野的像风 2021-02-02 06:34

Is there a way to stub method for only specific arguments. Something like this

boss.stub(:fire!).with(employee1).and_return(true)

If any other

2条回答
  •  一个人的身影
    2021-02-02 06:59

    You can try write your own stubbing method, with code like this

    fire_method = boss.method(:fire!)
    boss.stub!(:fire!) do |employee|  
      if employee == employee1
        true
      else
        fire_method.call(*args)
      end
    end
    

提交回复
热议问题