| 13 | | Rake::TestTask.new("test") do |t| |
| 14 | | t.libs << "spec" |
| 15 | | t.pattern = "spec/**/*_spec.rb" |
| 16 | | t.verbose = true |
| | 14 | require 'spec/rake/spectask' |
| | 15 | Spec::Rake::SpecTask.new(:spec) do |t| |
| | 16 | t.spec_files = FileList['spec/**/*_spec.rb'] |
| | 17 | t.spec_opts = ['--options', 'spec/spec.opts'] |
| | 18 | t.warning = true |
| | 19 | t.rcov = true |
| | 20 | t.rcov_dir = 'doc/output/coverage' |
| | 21 | t.rcov_opts = ['--exclude', 'spec,\.autotest'] |
| | 22 | end |
| | 23 | |
| | 24 | desc "Heckle each module and class in turn" |
| | 25 | task :heckle => :spec do |
| | 26 | root_modules = HECKLE_ROOT_MODULES |
| | 27 | spec_files = FileList['spec/**/*_spec.rb'] |
| | 28 | |
| | 29 | current_module, current_method = nil, nil |
| | 30 | heckle_caught_modules = Hash.new { |hash, key| hash[key] = [] } |
| | 31 | unhandled_mutations = 0 |
| | 32 | |
| | 33 | root_modules.each do |root_module| |
| | 34 | IO.popen("heckle #{root_module} -t #{spec_files}") do |pipe| |
| | 35 | while line = pipe.gets |
| | 36 | line = line.chomp |
| | 37 | |
| | 38 | if line =~ /^\*\*\* ((?:\w+(?:::)?)+)#(\w+)/ |
| | 39 | current_module, current_method = $1, $2 |
| | 40 | elsif line == "The following mutations didn't cause test failures:" |
| | 41 | heckle_caught_modules[current_module] << current_method |
| | 42 | elsif line == "+++ mutation" |
| | 43 | unhandled_mutations += 1 |
| | 44 | end |
| | 45 | |
| | 46 | puts line |
| | 47 | end |
| | 48 | end |
| | 49 | end |
| | 50 | |
| | 51 | if unhandled_mutations > 0 |
| | 52 | error_message_lines = ["*************\n"] |
| | 53 | |
| | 54 | error_message_lines << |
| | 55 | "Heckle found #{unhandled_mutations} " + |
| | 56 | "mutation#{"s" unless unhandled_mutations == 1} " + |
| | 57 | "that didn't cause spec violations\n" |
| | 58 | |
| | 59 | heckle_caught_modules.each do |mod, methods| |
| | 60 | error_message_lines << |
| | 61 | "#{mod} contains the following poorly-specified methods:" |
| | 62 | methods.each do |m| |
| | 63 | error_message_lines << " - #{m}" |
| | 64 | end |
| | 65 | error_message_lines << "" |
| | 66 | end |
| | 67 | |
| | 68 | error_message_lines << |
| | 69 | "Get your act together and come back " + |
| | 70 | "when your specs are doing their job!" |
| | 71 | |
| | 72 | puts "*************" |
| | 73 | raise error_message_lines.join("\n") |
| | 74 | else |
| | 75 | puts "Well done! Your code withstood a heckling." |
| | 76 | end |
| | 77 | end |
| | 78 | |
| | 79 | require 'spec/rake/verify_rcov' |
| | 80 | RCov::VerifyTask.new(:rcov => :spec) do |t| |
| | 81 | t.index_html = "doc/output/coverage/index.html" |
| | 82 | t.threshold = 100 |