Sha256: d99b799e7c9387352e5dfadc8895ec77be814c5ea913f4ff71548a2f1cf71e95

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

# original code by Ashley Moran:
# http://aviewfromafar.net/2007/11/1/rake-task-for-heckling-your-specs
desc 'Heckle each module and class'
task 'metrics:heckle' => 'metrics:coverage' do
  root_module = 'Yardstick'
  spec_files  = FileList['spec/uni/**/*_spec.rb']

  current_module = nil
  current_method = nil

  heckle_caught_modules = Hash.new { |hash, key| hash[key] = [] }
  unhandled_mutations = 0

  IO.popen("spec --heckle #{root_module} #{spec_files} 2>/dev/null") do |pipe|
    while line = pipe.gets
      case line = line.chomp
        when /\A\*\*\*\s+(#{root_module}(?:::)?(?:\w+(?:::)?)*)#(\S+)/
          current_module, current_method = $1, $2
        when "The following mutations didn't cause test failures:"
          heckle_caught_modules[current_module] << current_method
        when '+++ mutation'
          unhandled_mutations += 1
      end

      puts line
    end
  end

  if unhandled_mutations > 0
    error_message_lines = [ "*************\n" ]

    error_message_lines << "Heckle found #{unhandled_mutations} " \
      "mutation#{"s" unless unhandled_mutations == 1} " \
      "that didn't cause spec violations\n"

    heckle_caught_modules.each do |mod, methods|
      error_message_lines << "#{mod} contains the following " \
        'poorly-specified methods:'
      methods.each do |method|
        error_message_lines << " - #{method}"
      end
      error_message_lines << ''
    end

    error_message_lines << 'Get your act together and come back ' \
      'when your specs are doing their job!'

    raise error_message_lines.join("\n")
  else
    puts 'Well done! Your code withstood a heckling.'
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yardstick-0.9.6 tasks/metrics/heckle.rake
yardstick-0.9.5 tasks/metrics/heckle.rake
yardstick-0.9.4 tasks/metrics/heckle.rake
yardstick-0.9.3 tasks/metrics/heckle.rake