<commit_before>module AktionTestRails
  module Matchers
    module FactoryGirl
      module Validation
        def have_valid_factory(factory_name)
          ValidFactoryMatcher.new(factory_name)
        end

        class ValidFactoryMatcher < AktionTest::Matchers::Base
          def initialize(factory_name)
            @factory_name = factory_name
          end

          def matches?(subject)
            factory_exists? && factory_creates_valid_record?
          end

          def expectation
            ":#{@factory_name} to be a valid factory."
          end

          def problem
            message = "\n"
            if factory_exists?
              if @record.errors.full_messages.any?
                message << "Failed Validations:\n"
                @record.errors.full_messages.each do |error|
                  message << "  #{error}\n"
                end
              end
            else
              message << "No factory by the name :#{@factory_name} found\n"
            end
            message
          end

          def negative_problem
          end

          def description
            "has a valid factory named :#{@factory_name}"
          end

        protected

          def factory_exists?
            ::FactoryGirl.factories.registered?(@factory_name)
          end

          def factory_creates_valid_record?
            @record = ::FactoryGirl.build(@factory_name)
            @record.valid?
          end
        end
      end
    end
  end
end<commit_msg>update factory girl validation matcher to new matcher base updates<commit_after>module AktionTestRails
  module Matchers
    module FactoryGirl
      module Validation
        def have_valid_factory(factory_name)
          Matcher.new(factory_name)
        end

        class Matcher < AktionTest::Matchers::Base
          def initialize(factory_name)
            @factory_name = factory_name
          end

          def description
            "has a valid factory named :#{@factory_name}"
          end

        protected

          def expectation
            ":#{@factory_name} to be a valid factory."
          end

          def problems_for_should
            message = "\n"
            if factory_exists?
              if @record.errors.full_messages.any?
                message << "Failed Validations:\n"
                @record.errors.full_messages.each do |error|
                  message << "  #{error}\n"
                end
              end
            else
              message << "No factory by the name :#{@factory_name} found\n"
            end
            message.chomp
          end

          def problems_for_should_not
          end

          def perform_match!
            factory_exists? && factory_creates_valid_record?
          end

          def factory_exists?
            ::FactoryGirl.factories.registered?(@factory_name)
          end

          def factory_creates_valid_record?
            @record = ::FactoryGirl.build(@factory_name)
            @record.valid?
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06501143417183927, 'fraction_numerical': 0.0, 'mean_word_length': 1.4793522267206478, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2978373', 'n_tokens_mistral': 780, 'n_tokens_neox': 750, 'n_words': 192}