Commit Graph

4 Commits

Author SHA1 Message Date
Nate Holland 0e7c6e60f1
Run automatic cop fixes
This runs all of the automatic cops that came in since rubocop 0.68.
None of these changes were manual.
2020-01-17 14:43:34 -05:00
Christian Bruckmayer b86ec136b6
Raise KeyError instead of ArgumentError in Registry
to make use of did_you_mean gem.

The did_you_mean gem only supports NameError, NoMethodError
and KeyError. However, for NameError the message does also need
to match a certain format and we can not use a custom message
like 'Factory not registered ...'. Therefore using KeyError
is to only logical conclusion.

The did_you_mean gem makes use of the receiver attributes, but
in Ruby > 2.5 it is not possible to set the receiver and key attributes
on a KeyError (they are only set when the KeyError is raised in C).
We explored monkey patching KeyError for earlier versions of Ruby, but
it was a problematic solution.

Instead we can rescue the original KeyError, take the message from it,
which will already include the did_you_mean message, then customize
the message and re-raise a new KeyError with that customized message.
Starting in Ruby 2.6 this will not be necessary anymore
https://bugs.ruby-lang.org/issues/14313, so maybe we can get rid of it
for FactoryBot 6 or 7.

Fixes #992

Co-authored-by: Daniel Colson <danieljamescolson@gmail.com>
2018-12-16 22:25:04 -05:00
Daniel Colson 2e0b47639c
Remove deprecated factory lookup by class (#1212)
Closes #1196

We deprecated looking up factories by class in #877. We introduced
`allow_class_lookup` option so that people could disable the behavior
entirely after fixing the deprecation warning.

In preparation for factory_bot 5, I am removing the deprecation warning
and the `allow_class_lookup` option. It is no longer possible to look
up factories by class. This has also made the ClassKeyHash decorator
unnecessary. The behavior is technically a little different now
that we are using HashWithIndifferentAccess
instead of calling to_sym on the key, but it
should behave identically for any standard,
documented factory_bot usage.
2018-10-12 16:59:02 -04: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 lib/factory_girl/registry.rb (Browse further)