0
Minitest에서 Mocha를 사용하여 다른 스텁을 반환하는 함수를 스텁 싶습니다. 내가 byebug와 코드를 실행하면 이 코드Minitest/Mocha 중첩 스텁
@instance = stub('instance') do
stubs(:destroy).returns(true)
stubs(:id).returns(0)
end
find_by_id = stub do
stubs(:find_by_id).returns(nil) #default
stubs(:find_by_id).with(@instance.id).returns(@instance)
end
@user.stubs(:instances).returns(find_by_id)
입니다 @instance 정의됩니다 :
(byebug) @instance
#<Mock:instance>
그러나, find_by_id = 스텁 내에서 할
(byebug) @instance
nil
내가 읽은
here 스텁 대신 모의를 사용하는 방법도 있지만 작동하지 않습니다.
@instance가 블록 안에없는 이유는 이전에 정의 된 것과 같습니다.