Skip to content

Loading…

Use more verbose factories_spec.rb #123

Closed
aripollak opened this Issue · 2 comments

2 participants

@aripollak

The example here gives a better error message on failure:
https://github.com/thoughtbot/factory_girl/wiki/Testing-all-Factories-(with-RSpec)

@aripollak

Another possible addition is to include this around the context block, in case you have factories that are not for ActiveRecord models:

factory_class = factory.name.to_s.camelcase.safe_constantize
if factory_class && factory_class.ancestors.include?(ActiveRecord::Base)

or the duck-typed version (which I chose):

factory_class = factory.name.to_s.camelcase.safe_constantize
if factory_class && factory_class.method_defined?(:valid?)
@geoffharcourt geoffharcourt added a commit to geoffharcourt/suspenders that referenced this issue
@geoffharcourt geoffharcourt Use more verbose factories_spec.rb
Code from thoughtbot factory_girl wiki for testing that factories are
producting valid models. See issue #123.
bb14cdf
@croaky croaky added a commit that referenced this issue
@geoffharcourt geoffharcourt Use more verbose factories spec
Use code from factory girl wiki testing factories are producting valid
models. See issue #123.
84c3451
@croaky
thoughtbot, inc. member

The subject.errors.full_messages.join(',') bit has been in master for a few months. Thanks, @aripollak.

@croaky croaky closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.