class MutatorRails::SingleMutate

Public Instance Methods

base() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 51
def base
  path.basename.to_s.sub(path.extname, '').camelize
end
call() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 9
def call
  parms = BASIC_PARMS.dup
  parms << preface(path.basename) + base

  parms << '1> ' + log.to_s
  log_dir

  rerun(cmd(parms)) || first_run(parms)
end
cmd(parms) click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 95
def cmd(parms)
  spec_opt + COMMAND + parms.join(' ')
end
code_md5() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 55
def code_md5
  Digest::MD5.file(path).hexdigest
end
complete?(log) click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 107
def complete?(log)
  content = File.read(log)
  /^Subjects: / === content
end
failed?(log) click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 112
def failed?(log)
  content = File.read(log)
  /Failures:/ === content ||
    /ActiveRecord::PendingMigrationError/ === content
end
first_run(parms) click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 83
def first_run(parms)
  cmd = cmd(parms)

  if changed? || !complete?(log) || failed?(log)
    puts "[#{Time.current.iso8601}] #{cmd}"
    `#{cmd}` unless ENV['RACK_ENV'].eql?('test')
    guide.update(log, code_md5, spec_md5)
  end

  cmd
end
full_log() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 29
def full_log
  log_location.to_s + '.log'
end
log() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 19
def log
  if File.exist?(old_log)
    # repair - this is one time only
    guide.update(full_log, code_md5, spec_md5)
    File.rename(old_log, full_log)
  end

  full_log
end
log_correct?() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 118
def log_correct?
  guide.current?(log, code_md5, spec_md5)
end
log_dir() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 41
def log_dir
  log_location.dirname.tap do |dir|
    FileUtils.mkdir_p(dir)
  end
end
log_location() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 37
def log_location
  path.sub(APP_BASE, logroot).sub('.rb', '')
end
need_j1?() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 76
def need_j1?
  return false unless File.exist?(log)

  content = File.read(log)
  /Failures:/ === content
end
old_log() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 33
def old_log
  "#{log_location}_#{code_md5}_#{spec_md5}_#{MUTANT_VERSION}.log"
end
path() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 59
def path
  Pathname.new(file)
end
preface(base) click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 122
def preface(base)
  rest = file.sub(APP_BASE, '').sub(/(lib)\//, '').sub(base.to_s, '')
  return '' if rest == ''

  content = File.read(spec_file)
  d       = content.match(/RSpec.describe\s+([^ ,]+)/)
  cs      = d[1].split('::')
  cs.pop
  f = cs.join('::')
  f += '::' if f.present?
  f
end
rerun(cmd) click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 63
def rerun(cmd)
  return unless File.exist?(log)

  content = File.read(log)
  return unless /Failures:/ === content

  FileUtils.cp(log, '/tmp')
  cmd2 = cmd.sub('--use', '-j1 --use')
  puts log
  puts "[#{Time.current.iso8601}] #{cmd2}"
  `#{cmd2}` unless ENV['RACK_ENV'].eql?('test')
end
spec_file() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 103
def spec_file
  file.sub(APP_BASE, 'spec/').sub('.rb', '_spec.rb')
end
spec_md5() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 47
def spec_md5
  Digest::MD5.file(spec_file).hexdigest
end
spec_opt() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 99
def spec_opt
  "SPEC_OPTS=\"--pattern #{spec_file}\" "
end

Private Instance Methods

changed?() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 137
def changed?
  !log_correct?
end
logroot() click to toggle source
# File lib/mutator_rails/single_mutate.rb, line 141
def logroot
  MutatorRails::Config.configuration.logroot
end