rspec new syntax stub method with parameters and return fix value

1k views Asked by At

I want to stub object A for respond to message next with parameter 1 and return "B" String.

describe "some situation" do
  before do
    A = double("Some Object")
    A.stub(:next).with(1).and_return("B")
  end

  it "passes" do
    expect(A.next(1)).to eq(B)    
  end
end

I want to write A.stub(:next).with(1).and_return("B") line with new rspec syntax A.allow... but I could not find where to add the with part

1

There are 1 answers

0
Uri Agassi On BEST ANSWER

This is how the new syntax works:

allow(A).to receive(:next).with(1).and_return("B")