Sha256: c88bcfa1b27c31288c9f5c42946ec3c7e29b16713579f37c04d937f395cd33fb

Contents?: true

Size: 1.59 KB

Versions: 12

Compression:

Stored size: 1.59 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 :heckle => :verify_rcov do
  root_module = 'Yardstick'
  spec_files  = FileList['spec/**/*_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

12 entries across 12 versions & 2 rubygems

Version Path
dkubb-yardstick-0.1.0 tasks/heckle.rake
yardstick-0.9.2 tasks/heckle.rake
yardstick-0.9.1 tasks/heckle.rake
yardstick-0.9.0 tasks/heckle.rake
yardstick-0.8.0 tasks/heckle.rake
yardstick-0.7.0 tasks/heckle.rake
yardstick-0.6.0 tasks/heckle.rake
yardstick-0.5.0 tasks/heckle.rake
yardstick-0.4.0 tasks/heckle.rake
yardstick-0.3.0 tasks/heckle.rake
yardstick-0.2.0 tasks/heckle.rake
yardstick-0.1.0 tasks/heckle.rake