Commit Graph

10 Commits

Author SHA1 Message Date
Oliver Peate 7722017bc7 Adjust use_parent_strategy safely in specs
Uses a block-based helper so we can remove a global around hook.
2019-08-12 18:54:53 +01:00
Daniel Colson 3e1a941347 Do not reset use_parent_strategy on reload
Before this PR, `use_parent_strategy` was set on the configuration
instance. Since `FactoryBot.reload` wipes out the configuration, it also
ends up resetting `use_parent_strategy` back to `nil`.

This can cause problems when using factory_bot_rails with Spring, since
it calls `FactoryBot.reload` each time Spring forks. If
`use_parent_strategy` is set in a file that Spring preloads, like in an
initializer, then the value will get wiped out.

With this PR, we set `use_parent_strategy` directly on FactoryBot,
rather than on the configuration instance, and so reloading no longer
has any effect.
2019-01-04 15:47:32 -05:00
Daniel Colson bf04aaa068 Autocorrect all static attributes to dynamic
Most of this was fixed by adding the `attribute-defined-statically-cop`
branch of `thoughtbot/rubocop-rspec` to the Gemfile and running:

```sh
  rubocop \
    --require rubocop-rspec \
    --only FactoryBot/AttributeDefinedStatically \
    --auto-correct
```

I had to update the cucumber tests manually, and I realized our changes
don't handle `ignore` blocks or blocks with arity 1 that use the yielded
DefinitionProxy. I will update
https://github.com/rubocop-hq/rubocop-rspec/pull/666to handle these
cases.
2018-09-14 19:27:13 +00:00
Oli Peate 01d81f54b5 Remove unnecessary spec_helper requires
https://github.com/rspec/rspec/wiki#rspec
2018-05-21 18:03:28 +01:00
Avielle c716ce01b4 Replace 'girl' with 'bot' everywhere (#1051)
Also: add a deprecation warning to factory_girl, asking users to switch to
factory_bot

https://github.com/thoughtbot/factory_girl/issues/921
2017-10-20 15:20:28 -04:00
Ryan Ringler 69b72e66de Add use_parent_strategy option for building associations (#961)
This change means that:

1. The option is turned on, and
2. A Post has a User (for example), and
3. We build an association
4. Then the User is built too.

With the flag off, the User would be created, which matches current
behaviour.

See: https://github.com/thoughtbot/factory_girl/pull/749
2016-12-16 05:28:09 -05:00
Andy Waite and Josh Clayton b9e1dde7e8 Add *_pair methods to create only two records
This introduces a set of methods for each build strategy where only two
records are created. Because the *_list methods can create an arbitrary
number (often too high), this introduces *_pair to ensure only two
records are created (and the number 2 doesn't need to be specified in
the call).
2013-11-01 17:32:50 -04:00
Joshua Clayton b095f24598 Convert to expect syntax 2013-01-18 13:58:36 -05:00
Josh Clayton and Joel Oliveira 95a4626daa Support *_list for all (including custom) strategies 2012-05-04 14:56:22 -04:00
Joshua Clayton c8c1a801ed Add ability to register custom strategies 2012-04-23 21:28:20 -05:00