How do I stub things in MiniTest?

前端 未结 8 922
面向向阳花
面向向阳花 2020-12-02 09:46

Within my test I want to stub a canned response for any instance of a class.

It might look like something like:

Book.stubs(:title).any_instance().ret         


        
8条回答
  •  天涯浪人
    2020-12-02 10:20

    I use minitest for all my Gems testing, but do all my stubs with mocha, it might be possible to do all in minitest with Mocks(there is no stubs or anything else, but mocks are pretty powerful), but I find mocha does a great job, if it helps:

    require 'mocha'    
    Books.any_instance.stubs(:title).returns("War and Peace")
    

提交回复
热议问题