简体   繁体   中英

Multiple invocations of same method on a mock with minitest

I am using the version of minitest with Ruby 1.9.3 How do I test for multiple invocations of a mock with it? I need something like

mockObject.expect.times(2) :method, [return_1 first time, return_2 second time] 
mockObject.verify

Is there a way to achieve this?

You need to call expect for each time the method is to be called.

mockObject.expect :method, return_1, [first, time, args]
mockObject.expect :method, return_2, [second, time, args]

# run your code using the mock object

mockObject.verify

Unfortunately my minitest version is older. This has only been supported since this commit. https://github.com/seattlerb/minitest/commit/7a6f1818877c6c8a83a0e6680d5fc23ec32fa633#diff-00a18d559ad9a1e984068e38e5009047

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM