문제

How can I create a mock / stub for the following object using RSpec:

User.current.instance.custom_field

returning a specific such as "foo" value

도움이 되었습니까?

해결책

rspec provides an option to stub chain methods

User.stub_chain(:current, :instance, :custom_field).and_return("foo")

Have a look at the documentation for chain stub here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top