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

15 commits

Author SHA1 Message Date
Yudai Takada
09053ea0ef
Fix some typo (#1542)
* Fix typo "delcaration" -> "declaration"

* Fix typo "Ususually" -> "Usually"

* Fix typo "assocition" -> "association"

* Fix typo "vaue" -> "value"
2022-06-08 07:01:10 -04:00
Daniel Colson
5f1a1de114 Run standardrb
This commit applies the changes from running `standardrb --fix`
2020-06-10 17:11:39 -04:00
Richie Thomas
161b7969c1
Refactor definition_proxy_spec.rb to conform to Let's Not style (#1342)
* Refactor definition_proxy_spec.rb to conform to Let's Not style

* Fix what appears to be a typo in naming of block-defined variable
2019-10-25 10:03:09 -07:00
Daniel Colson
f898371f8f
Improve error for static attribute attempts
Some people upgrade straight from factory_bot < 4.11 to factory_bot >=
5.0 and miss the deprecation cycle for static attributes. I have gotten
some feedback that the NoMethodError is confusing. Since we know that in
most cases people are seeing the NoMethodError when trying to define
static attributes, we offer them a "Did you mean?"-style suggestion for
how they might update to dynamic attributes.

I removed the extra test for setter methods. It was a remnant of
something I had removed in #1200. I see no reason to have special
treatment for setters at this point.

Closes https://github.com/thoughtbot/factory_bot/issues/1272
2019-04-26 12:47:12 -04:00
Daniel Colson
79331a3863 Allow inline sequences in traits to have same name
Fixes #1257

When sequence rewinding was first introduced in #1078 it only applied to
globally defined sequences. To get rewinding to work for inline
sequences as well we registered them "privately" in the global registry
in #1164. Unfortunately in #1164 we did not take inline sequences inside
traits into consideration. Since trait names are not unique, it is
possibly to get a `FactoryBot::DuplicateDefinitionError` when defining
two sequences that have the same name in two traits that have the same
name.

This PR abandons the idea of "privately" registering inline sequences,
and instead keeps a separate list of all the inline sequences just for
the purpose of rewinding them.
2019-02-15 17:10:27 -05:00
Jared Beck
bfeec78f29 Raise helpful error block given to association
Closes #1033

> Arguably, association should raise and let the developer know
> they're using it in an unexpected way. I'd love to see a PR for
> that (with a test!), so if you're interested in contributing that,
> please do!
> https://github.com/thoughtbot/factory_girl/issues/1032#issuecomment-329297006

Co-authored-by: Daniel Colson <danieljamescolson@gmail.com>
2018-10-28 19:12:34 -04:00
Hunter Braun
89ee4a4524 [Rubocop] Style Cop Offenses (#1208) 2018-10-07 18:02:54 -04:00
Daniel Colson
5b31b56d65 Remove warning about setter methods
This warning made sense when we had static attributes, since
somebody might try to write something like:

```rb
factory :composer do
  self.name = "Daniel"
end
```

That would create a static declaration when the factory was defined,
then raise the error about avoiding writers when the factory was run.

Now this code will raise a NoMethodError right away when the factory is
being defined.
2018-09-28 16:59:48 -04:00
Daniel Colson
512ebf938f Manually raise NoMethodError in definition proxy
Inside `super` Ruby calls `inspect`, but since we have undefined
`inspect` on the definition proxy we end up declaring an implicit
`inspect` attribute. We do the same thing with `methods` and
`singleton_methods`, and then `inspect` again. By the time we finally
see the NoMethodError, we see it on a
`FactoryBot::Declaration::Implicit` instead of the definition proxy.

By raising the NoMethodError manually we avoid this nonsense and have
the added benefit of showing the name of the factory where the missing
method came from.
2018-09-28 15:57:58 -04:00
Colin Ross
a56b68bc9c Fix assorted RuboCop spacing volations (#1203)
* Alphabetize gem listing in various Gemfiles [Rubocop Bundler/OrderedGems]

* Fix alignment of if/else/end statement [Rubocop Layout/ElseAlignment]

* Method definitions should have a empty line between them [Rubocop Layout/EmptyLineBetweenDefs]

* Modules, Classes, and blocks should have an empty line around them [Rubocop]

Cops:
Layout/EmptyLinesAroundBlockBody
Layout/EmptyLinesAroundModuleBody
Layout/EmptyLinesAroundClassBody
Layout/EmptyLinesAroundAccessModifier

* Keep a blank line before and after access modifiers [Rubocop Layout/EmptyLinesAroundAccessModifier]

* Remove misc extra whitespace [Rubocop Layout/ExtraSpacing]

* Indent the first line of the right-hand-side of a multi-line assignment [Rubocop Layout/IndentAssignment]

* Remove extraneous whitespace [Rubocop]

Cops:
  Layout/IndentationWidth
  Layout/LeadingCommentSpace
  Layout/SpaceAroundEqualsInParameterDefault
  Layout/SpaceInsideArrayLiteralBrackets
  Layout/SpaceInsideBlockBraces
  Layout/SpaceInsideParens
  Layout/TrailingBlankLines

* Revert rubocop changes to gemfiles; exclude files from rubocop checks

The files in gemfiles/ are generated by Appraisal, so we shouldn't edit them. Instead, let's tell RuboCop to exclude this directory.
2018-09-27 21:35:05 -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
805933eed2 Remove static attributes from the definition proxy
This changes the signature of `add_attribute`, so if you pass a value at
all you will now get an `ArgumentError`. Any `method_missing`-style
static attribute definitions will become `NoMethodError`s.
2018-09-14 19:27:13 +00:00
Daniel Colson
f1d7ae3cc1 Register inline sequence to allow for rewinding
This was originally opened as #1078, but this addresses the review
comments on that PR.

By registering the inline sequences, we allow them to get rewound with
`FactoryBot.rewind_sequences`. We register them with
`__#{factory_name}_#{sequence_name}__` to avoid conflicting with any
reasonably named global sequences, and to hint that we should not be
generating values from these sequences directly.

Co-authored-by: Damian Le Nouaille <dam@dln.name>
Co-authored-by: Damian Galarza <galarza.d@gmail.com>
2018-09-08 02:29:30 +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
Renamed from spec/factory_girl/definition_proxy_spec.rb (Browse further)