Sha256: e34006c403d98f9f304b0ec29e26ab70f28fcb6410bf2ae8e8e4508f1a1f5aed

Contents?: true

Size: 1.82 KB

Versions: 21

Compression:

Stored size: 1.82 KB

Contents

require "rubygems"
require "spec"
require "spec/rake/spectask"
require "pathname"

all_tests = {}
all_files = Dir["**/*.rb"]

all_files.each do |filename|
  if filename =~ /\//
    sub = filename.split("/")
    subfilename = sub[1]

    unless all_tests.has_key?(sub[0])
      all_tests.merge!({sub[0] => {}})
    end

    test = {subfilename[0..-4] => subfilename}
    all_tests[sub[0]].merge!(test)
  elsif filename =~ /helper.rb/
    next 
  else
    test = {filename[0..-4] => filename}
    all_tests.merge!(test)
  end
end

spec_opts = ["--color", "--require rubygems"] #, "--format OperaHelperFormatter"]
spec_files = []

# All tests
desc "All tests"
Spec::Rake::SpecTask.new("test") do |t|
  all_tests.each do |testname, testfile|
    if testfile.kind_of?(Hash)
      testfile.each do |subtestname, subtestfile|
        spec_files.push testname + "/" + subtestfile
      end
    else
      spec_files.push testfile
    end
  end

  t.spec_opts = spec_opts
  t.spec_files = [spec_files]
end

namespace :test do
  all_tests.each_pair do |testname, testfile|
    if testfile.kind_of?(Hash)
      testfile.each_pair do |subtestname, subtestfile|
        testfile[subtestname] = testname + "/" + subtestfile
      end

      desc "All " + testname + " tests"
      Spec::Rake::SpecTask.new(testname) do |t|
        t.spec_opts = spec_opts
        t.spec_files = testfile.values
      end

      namespace testname do
        testfile.each_pair do |subtestname, subtestfile|
          desc subtestname + " tests"
          Spec::Rake::SpecTask.new(subtestname) do |t|
            t.spec_opts = spec_opts
            t.spec_files = [subtestfile]
          end
        end
      end
    else
      desc testname + " tests"
      Spec::Rake::SpecTask.new(testname) do |t|
        t.spec_opts = spec_opts
        t.spec_files = [testfile]
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
operawatir-0.3-jruby utils/Rakefile