Iago
Iago

Reputation: 308

RSpec: Create mock / stub a hierarchical object

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

Upvotes: 0

Views: 98

Answers (1)

usha
usha

Reputation: 29349

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

Upvotes: 2

Related Questions