module Mutant

Constants

VERSION

Attributes

output[RW]

Public Class Methods

included(klass) click to toggle source
# File lib/ruby-mutant/base.rb, line 11
def self.included(klass)
    klass.extend(ClassMethods)
end
new(*args) click to toggle source
# File lib/ruby-mutant/base.rb, line 97
def initialize(*args)
    @output = Output.new
end

Private Instance Methods

check_required_attrs() click to toggle source

Checks to see if any `required_attr` has been set, if so check to see if each one is defined in either the .run() definition or the mutation's `attr_accesor`. TODO need to also check that these required attributes have values

Parameters:

Returns:

An array of errors, of type `MutationMissingRequiredVarException`, for each missing required attribute.

# File lib/ruby-mutant/base.rb, line 136
def check_required_attrs
    # In this we need to compare what we define in
    # required_attr(*attrs) against what we have defined in
    # the mutation vs what we pass into the run() definition
    errors = []
    puts 'Mutant::check_required_attrs'
    self.required_attr.each do |attr|
        if !self.respond_to?(attr)
            # Our attribute is not defined on our mutation class
            # So we will build the error to return to the run()
            # method, which can determine how we proceed
            err = MutationMissingRequiredVarException.new(
                                msg="A property that is marked as required is not defined on the mutation: #{attr}",
                                prop=attr)
            errors << err
        end
    end
    errors
end
validate() click to toggle source

This will run all ou validation functions on our mutation class. This will return an array of MutationValidationException, to the class method, run()

Parameters:

Returns:

errors.  An array of errors representing all validation methods that have failed.

(defaults to `[]`)

# File lib/ruby-mutant/base.rb, line 111
def validate
    errors = []
    self.public_methods.each do |m|
        if m.to_s.start_with?('validate_') && m.to_s.end_with?('?')
            # execute validation method
            res = self.send(m)

            # unless the response is truthy
            unless res
                errors << MutationValidationException.new(msg='Validator has returned false', validator=m)
            end
        end
    end
    errors
end