Вопрос

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