Sha256: e0c768d5dc7a436a6d5787d5ba2690a1c047c80f8eca7b7a4e9d46b0de72cf7a

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

require 'rake'
require 'cuke_modeler'
require 'cql'

require 'cuke_cataloger/version'
require 'cuke_cataloger/unique_test_case_tagger'

module CukeCataloger

  extend Rake::DSL

  # todo - test these better

  def self.create_tasks

    desc 'Add unique id tags to tests in the given directory'
    task 'tag_tests', [:directory, :prefix] do |t, args|
      location = args[:directory] || '.'
      prefix = args[:prefix] || '@test_case_'

      puts "Tagging tests in '#{location}' with tag '#{prefix}'\n"

      tagger = CukeCataloger::UniqueTestCaseTagger.new
      tagger.tag_tests(location, prefix)
    end

    desc 'Scan tests in the given directory for id problems'
    task 'validate_tests', [:directory, :prefix, :out_file] do |t, args|
      location = args[:directory] || '.'
      prefix = args[:prefix] || '@test_case_'

      puts "Validating tests in '#{location}' with tag '#{prefix}'\n"

      results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(location, prefix)
      report_text = "Validation Results\nProblems found: #{results.count}\n\n"


      results_by_category = Hash.new { |hash, key| hash[key] = [] }

      results.each do |result|
        results_by_category[result[:problem]] << result
      end

      results_by_category.keys.each do |problem_category|
        report_text << "#{problem_category} problems: #{results_by_category[problem_category].count}\n"
      end

      results_by_category.keys.each do |problem_category|
        report_text << "\n\n#{problem_category} problems (#{results_by_category[problem_category].count}):\n"

        results_by_category[problem_category].each do |result|
          report_text << "#{result[:test]}\n"
        end
      end

      if args[:out_file]
        puts "Problems found: #{results.count}"
        File.open(args[:out_file], 'w') { |file| file.write(report_text) }
      else
        puts report_text
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cuke_cataloger-1.3.1 lib/cuke_cataloger.rb
cuke_cataloger-1.3.0 lib/cuke_cataloger.rb