Expect method call and proxy to original method with RSpec

前端 未结 1 1737
醉话见心
醉话见心 2021-01-18 06:01

I want to discover with BDD missing :include params for ActiveRecord::Base.find method. So my idea is to have in spec something like this:

ActiveRecord::Base         


        
相关标签:
1条回答
  • 2021-01-18 06:27

    I think I had the same problem here. In your particular case I would do this which I find quite clean.

    original_method = ActiveRecord::Base.method(:find)
    ActiveRecord::Base.should_receive(:find).once do (*args)
      original_method.call(*args)
    end
    

    I believe you could extend the Rspec Mocks::MessageExpectation class to include the and_proxy_to_original_method method, shouldn't be too hard, but I haven't looked.

    0 讨论(0)
提交回复
热议问题