Milovan Zogovic Milovan Zogovic - 1 year ago 85
Ruby Question

Rspec stubbing method for only specific arguments

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


If any other employee is passed to!
method, I'll get
boss received unexpected message
error, but what I would really like is just to override the method for specific argument, and leave it be for all others.

Any ideas how this can be done?

Answer Source

You can add a default stub for the fire! method which will call original implementation:


Rspec 3 Syntax (@pk-nb)

allow(boss).to receive(:fire!).and_call_original
allow(boss).to receive(:fire!).with(employee1).and_return(true)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download