Get errors from FactoryGirl.lint

I have inherited a number of FactoryGirl factories that actually don't work, and I'm trying to raise them to tobacco. Part of this was use FactoryGirl.lint. Until now, however, I have been able to find which factories fail, and run for any single person

x = FactoryGirl.build :invalid_factory
x.valid? # returns false as expected
x.errors # prints out the validation errors for that object

What I would like to do is not do this for every factory. Is there a quick way to get FactoryGirl.lintto write out errors that every invalid factory has? Flag for transmission, parameter for installation? Documentation is extremely rare in.lint

+4
source share
1 answer

FactoryGirl.factories, factory.

FactoryGirl.factories.map(&:name).each do |factory_name|
    describe "#{factory_name} factory" do

      # Test each factory
      it "is valid" do
        factory = FactoryGirl.build(factory_name)
        if factory.respond_to?(:valid?)
          # the lamba syntax only works with rspec 2.14 or newer;  for earlier versions, you have to call #valid? before calling the matcher, otherwise the errors will be empty
          expect(factory).to be_valid, lambda { factory.errors.full_messages.join("\n") }
        end
      end

script FactoryGirl , RSpec Guard, , .

+6

All Articles