Sha256: 29f6a0ccf80c3e2e44dd7f8188787d3e421e54278c5f2f93f40d4f87d79fba6b

Contents?: true

Size: 1.77 KB

Versions: 4

Compression:

Stored size: 1.77 KB

Contents

require 'rake'

module Assert; end
module Assert::RakeTasks; end

require 'assert/rake_tasks/irb'
require 'assert/rake_tasks/scope'
require 'assert/rake_tasks/test_task'

module Assert::RakeTasks

  FILE_SUFFIX = "_test.rb"

  # Setup the rake tasks for testing
  # * add 'include Assert::RakeTasks' to your Rakefile
  def self.included(receiver)
    # auto-build rake tasks for the ./test files (if defined in ./test)
    self.for('test') if File.exists?(File.expand_path('./test', Dir.pwd))
  end

  def self.for(test_root='test')
    self.irb_task(Assert::RakeTasks::Irb.new(test_root.to_s))
    self.to_tasks(Assert::RakeTasks::Scope.new(test_root.to_s))
  end

  class << self
    include Rake::DSL if defined? Rake::DSL

    def irb_task(irb)
      if irb.helper_exists?
        desc irb.description
        task irb.class.task_name do
          sh irb.cmd
        end
      end
    end

    def to_tasks(scope)
      # if there is a test task for the scope
      if (scope_tt = scope.to_test_task)
        # create a rake task to run it
        desc scope_tt.description
        task scope_tt.name do
          RakeFileUtils.verbose(scope_tt.show_loaded_files?) { ruby scope_tt.ruby_args }
        end
      end

      # create a namespace for the scope
      namespace scope.namespace do
        # for each test task in the scope, create a rake task to run it
        scope.test_tasks.each do |test_file_tt|
          desc test_file_tt.description
          task test_file_tt.name do
            RakeFileUtils.verbose(test_file_tt.show_loaded_files?) { ruby test_file_tt.ruby_args }
          end
        end

        # recusively generate rake tasks for each sub-scope in the scope
        scope.scopes.each do |sub_scope|
          self.to_tasks(sub_scope)
        end
      end

    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
assert-0.7.3 lib/assert/rake_tasks.rb
assert-0.7.2 lib/assert/rake_tasks.rb
assert-0.7.1 lib/assert/rake_tasks.rb
assert-0.7.0 lib/assert/rake_tasks.rb