設定器在一個RSpec單元測試我已經定義像這樣的模擬:存根上的RSpec instance_double
let(:point) { instance_double("Point", :to_coords => [3,2]) }
在點I類也有setter,它是在類下試驗中使用(這是稱爲Robot
)。我想存根二連擊測試Robot#move
。這是錯誤的代碼,我到目前爲止有:
describe "#move" do
it "sets @x and @y one step forward in the direction the robot is facing" do
point.stub(:coords=).and_return([4,2])
robot.move
expect(robot.position).to eq([4,2])
end
end
這裏的錯誤消息我得到:
Double "Point (instance)" received unexpected message :stub with (:coords=)