I have some code that uses .push
.
I want to write a unit test that tests the failure scenario of this code, but i can't figure out the syntax.
My code looks like this
if object.groups.push(group)
flash[:notice] = I18n.t(".success")
else
flash[:alert] = I18n.t(".failure")
end
I've tried to stub out the .push
method so it returns false, but it still returns true.
My stubbing attempts are below:
object.groups.should_receive(:push).with(group).and_return(false)
allow(object.groups).to receive(:push).with(group).and_call_original
Am i going about this the wrong way?
question from:
https://stackoverflow.com/questions/65829913/stub-push-method-in-rspec 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…