Class: MutatorRails::SingleMutate
- Inherits:
-
Object
- Object
- MutatorRails::SingleMutate
- Defined in:
- lib/mutator_rails/single_mutate.rb
Instance Method Summary collapse
- #base ⇒ Object
- #call ⇒ Object
- #cmd(parms) ⇒ Object
- #code_md5 ⇒ Object
- #complete?(log) ⇒ Boolean
- #failed?(log) ⇒ Boolean
- #first_run(parms) ⇒ Object
- #full_log ⇒ Object
- #log ⇒ Object
- #log_correct? ⇒ Boolean
- #log_dir ⇒ Object
- #log_location ⇒ Object
- #need_j1? ⇒ Boolean
- #old_log ⇒ Object
- #path ⇒ Object
- #preface(base) ⇒ Object
- #rerun(cmd) ⇒ Object
- #spec_file ⇒ Object
- #spec_md5 ⇒ Object
- #spec_opt ⇒ Object
Instance Method Details
#base ⇒ Object
51 52 53 |
# File 'lib/mutator_rails/single_mutate.rb', line 51 def base path.basename.to_s.sub(path.extname, '').camelize end |
#call ⇒ Object
9 10 11 12 13 14 15 16 17 |
# 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) ⇒ Object
95 96 97 |
# File 'lib/mutator_rails/single_mutate.rb', line 95 def cmd(parms) spec_opt + COMMAND + parms.join(' ') end |
#code_md5 ⇒ Object
55 56 57 |
# File 'lib/mutator_rails/single_mutate.rb', line 55 def code_md5 Digest::MD5.file(path).hexdigest end |
#complete?(log) ⇒ Boolean
107 108 109 110 |
# File 'lib/mutator_rails/single_mutate.rb', line 107 def complete?(log) content = File.read(log) /^Subjects: / === content end |
#failed?(log) ⇒ Boolean
112 113 114 115 116 |
# 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) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# 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 ⇒ Object
29 30 31 |
# File 'lib/mutator_rails/single_mutate.rb', line 29 def full_log log_location.to_s + '.log' end |
#log ⇒ Object
19 20 21 22 23 24 25 26 27 |
# 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? ⇒ Boolean
118 119 120 |
# File 'lib/mutator_rails/single_mutate.rb', line 118 def log_correct? guide.current?(log, code_md5, spec_md5) end |
#log_dir ⇒ Object
41 42 43 44 45 |
# 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 ⇒ Object
37 38 39 |
# File 'lib/mutator_rails/single_mutate.rb', line 37 def log_location path.sub(APP_BASE, logroot).sub('.rb', '') end |
#need_j1? ⇒ Boolean
76 77 78 79 80 81 |
# 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 ⇒ Object
33 34 35 |
# File 'lib/mutator_rails/single_mutate.rb', line 33 def old_log "#{log_location}_#{code_md5}_#{spec_md5}_#{MUTANT_VERSION}.log" end |
#path ⇒ Object
59 60 61 |
# File 'lib/mutator_rails/single_mutate.rb', line 59 def path Pathname.new(file) end |
#preface(base) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 |
# 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) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# 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 ⇒ Object
103 104 105 |
# File 'lib/mutator_rails/single_mutate.rb', line 103 def spec_file file.sub(APP_BASE, 'spec/').sub('.rb', '_spec.rb') end |
#spec_md5 ⇒ Object
47 48 49 |
# File 'lib/mutator_rails/single_mutate.rb', line 47 def spec_md5 Digest::MD5.file(spec_file).hexdigest end |
#spec_opt ⇒ Object
99 100 101 |
# File 'lib/mutator_rails/single_mutate.rb', line 99 def spec_opt "SPEC_OPTS=\"--pattern #{spec_file}\" " end |