Mocking chain of methods in rspec

≡放荡痞女 提交于 2019-12-05 22:02:22

问题


There are a chain of methods which gets a user object. I am trying to mock the following to return a user in my Factory Girl

@current_user = AuthorizeApiRequest.call(request.headers).result

I can mock the object up until the call method but I'm stuck at mocking the result method

allow(AuthorizeApiRequest).to receive(:call).and_return(:user)

回答1:


I found I need to use receive_message_chain

So this worked for me.

allow(AuthorizeApiRequest).to receive_message_chain(:call, :result).and_return(user)


来源:https://stackoverflow.com/questions/40571911/mocking-chain-of-methods-in-rspec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!