Factory_bot: What does "build_stubbed" means?

Created on 18 Apr 2017  路  1Comment  路  Source: thoughtbot/factory_bot

Hello, I am new to factory_girl. Sorry if I asked some stupid question.

In GETTING_STARTED.md, there is one thing called build_stubbed.

# Returns an object with all defined attributes stubbed out
stub = build_stubbed(:user)

The comment is not really helpful, can anyone please explain more about this? Perhaps we can update the readme to help out people to understand too.

Most helpful comment

Check out more here: _Use Factory Girl's build_stubbed for a Faster Test Suite_

build_stubbed is the younger, more hip sibling to build; it instantiates and assigns attributes just like build, but that鈥檚 where the similarities end. It makes objects look look _[sic]_ like they鈥檝e been persisted, creates associations with the build_stubbed strategy (whereas build still uses create), and stubs out a handful of methods that interact with the database and raises if you call them. This leads to much faster tests and reduces your test dependency on a database.

>All comments

Check out more here: _Use Factory Girl's build_stubbed for a Faster Test Suite_

build_stubbed is the younger, more hip sibling to build; it instantiates and assigns attributes just like build, but that鈥檚 where the similarities end. It makes objects look look _[sic]_ like they鈥檝e been persisted, creates associations with the build_stubbed strategy (whereas build still uses create), and stubs out a handful of methods that interact with the database and raises if you call them. This leads to much faster tests and reduces your test dependency on a database.

Was this page helpful?
0 / 5 - 0 ratings