Module: Assert::RakeTasks

Includes:
Rake::DSL
Defined in:
lib/assert/rake_tasks.rb,
lib/assert/rake_tasks.rb,
lib/assert/rake_tasks/irb.rb,
lib/assert/rake_tasks/scope.rb,
lib/assert/rake_tasks/test_task.rb

Defined Under Namespace

Classes: Irb, Scope, TestTask

Constant Summary collapse

FILE_SUFFIX =
"_test.rb"

Class Method Summary collapse

Class Method Details

.for(test_root = 'test') ⇒ Object



21
22
23
24
# File 'lib/assert/rake_tasks.rb', line 21

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

.included(receiver) ⇒ Object

Setup the rake tasks for testing

  • add ‘include Assert::RakeTasks’ to your Rakefile



16
17
18
19
# File 'lib/assert/rake_tasks.rb', line 16

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

.irb_task(irb) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/assert/rake_tasks.rb', line 29

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

.to_tasks(scope) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/assert/rake_tasks.rb', line 38

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