1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
Commit graph

13 commits

Author SHA1 Message Date
Daniel Colson
5f1a1de114 Run standardrb
This commit applies the changes from running `standardrb --fix`
2020-06-10 17:11:39 -04:00
Daniel Colson
1d6170af2b Add option for verbose linting
This has come up a few times, and I can see why it might be helpful to
have access to full backtraces when debugging a factory error uncovered
by `FactoryBot.lint`. But since most of the time I don't want the extra
noise from the backtrace, I added this as a verbose option.

The default message is still:

```
The following factories are invalid:
* user - undefined method `save!' for #<User:0x00007ff0cbc89100>
* admin - undefined method `save!' for #<User:0x00007ff0cbc73e40>
```

And with the verbose option (usually with more lines of backtrace):

```
The following factories are invalid:
* user - undefined method `save!' for #<User:0x00007ff0cbc89100>
  /Users/.../thoughtbot/factory_bot/lib/factory_bot/evaluation.rb:18:in `create'
  /Users/.../factory_bot/lib/factory_bot/strategy/create.rb:12:in `block in result'

* admin - undefined method `save!' for #<User:0x00007ff0cbc73e40>
  /Users/.../thoughtbot/factory_bot/lib/factory_bot/evaluation.rb:18:in `create'
  /Users/.../factory_bot/lib/factory_bot/strategy/create.rb:12:in `block in result'
```

I moved the linting option defaults out of the FactoryBot.lint method
and into keyword argument defaults in Linter#initialize. This seems a
bit cleaner, and now we will get an error if we pass an option we don't
understand (before 6e511597 we had a test that passed in a bogus
option)

Closes #710
Closes #1124

I am opening a new PR since the original PR is years old and it seemed
unkind to request changes after so long. Instead I will list the authors
as co-authors.

Co-authored-by: Jack Kinsella <jack.kinsella@gmail.com>
Co-authored-by: Jasper Woudenberg <mail@jasperwoudenberg.com>
2018-11-27 12:04:38 -05:00
Daniel Colson
6e511597c8
Remove unhelpful lint specs
These specs have no expectations, and they are passing
`validate_traits` as an option, which is not an option the linter
understands.

Since the first spec is already covered by "allows for selective
linting" above, and what I assume the second spec was meaning to cover
is covered by the trait specs, I see no reason to keep these around.
2018-11-19 00:04:55 -05:00
Susan Wright
2995978188 Rubocop: Fix Layout/IndentHeredoc issues (#1215) 2018-10-07 22:46:58 -04:00
Daniel Colson
0473865b93 Remove static attributes
Co-authored-by: George Wambold <georgewambold@gmail.com>
2018-09-14 19:27:13 +00: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
Oliver Peate
0dadb2f19f Allow linting factory strategy to be specified (#1019) 2017-09-28 08:22:16 -04:00
Andrew Peterson
702487072c FactoryGirl.lint can lint traits
Why?

Traits are another way to extend or modify behavior of a factory;
because of this, applied traits may result in invalid factories, even if
the base factory is valid.

To enable this functionality, use:

    FactoryGirl.lint traits:true

Note that, because FactoryGirl uses the `create` strategy when linting,
this may greatly slow the time to lint factories.
2016-02-05 09:00:37 -05:00
Joshua Clayton
f451e4a419 Fresh pass at displaying more detail during linting 2014-10-17 16:40:39 -04:00
Joshua Clayton
5f465f718f Allow selective linting
Closes #653
2014-05-30 11:28:58 -04:00
Joshua Clayton
6a692fe711 Add FactoryGirl.lint to ensure all factories are valid
This commit adds FactoryGirl.lint, which iterates over each defined
factory, builds it, and ensures it is valid. If any factories are
invalid, an exception is raised and includes the names of each invalid
factory.
2014-02-07 22:21:08 -05:00