Class: Gemma::RakeTasks::MinitestTasks

Inherits:
Plugin
  • Object
show all
Defined in:
lib/gemma/rake_tasks/minitest_tasks.rb

Overview

Create tasks to run minitest tests. By default, the require_paths from the gemspec and the gem’s test directory are placed on the load path, and the test_files given in the gemspec are executed as tests.

Minitest works on both 1.8 and 1.9, and it’s mostly compatible with Test::Unit tests.

This plugin is based on the ‘Rake::TestTask` that comes bundled with rake. If you need an option that isn’t exposed by the plugin, you can modify the ‘TestTask` object directly in a block passed to #with_test_task.

Instance Attribute Summary collapse

Attributes inherited from Plugin

#gemspec

Instance Method Summary collapse

Constructor Details

#initialize(gemspec) ⇒ MinitestTasks

Returns a new instance of MinitestTasks.

Parameters:

  • gemspec (Gem::Specification)


19
20
21
22
23
24
25
26
# File 'lib/gemma/rake_tasks/minitest_tasks.rb', line 19

def initialize gemspec
  super(gemspec)

  # Defaults.
  @task_name = :test
  @files = gemspec.test_files.dup
  @with_test_task = nil
end

Instance Attribute Details

#filesArray<String>

The files to test; defaults to the test_files from the gemspec.

Returns:

  • (Array<String>)


40
41
42
# File 'lib/gemma/rake_tasks/minitest_tasks.rb', line 40

def files
  @files
end

#task_nameSymbol

Name of rake task used to run the test; defaults to test.

Returns:

  • (Symbol)


33
34
35
# File 'lib/gemma/rake_tasks/minitest_tasks.rb', line 33

def task_name
  @task_name
end

Instance Method Details

#create_rake_tasksnil

Internal method; see Plugin#create_rake_tasks.

Returns:

  • (nil)


64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/gemma/rake_tasks/minitest_tasks.rb', line 64

def create_rake_tasks
  unless self.files.empty?
    require 'rake/testtask'
    Rake::TestTask.new(self.task_name) do |tt|
      tt.libs        = gemspec.require_paths.dup
      tt.libs       << 'test'
      tt.test_files  = self.files
      tt.ruby_opts  << '-rubygems' << '-rbundler/setup'
      @with_test_task.call(tt) if @with_test_task
    end
  end
  nil
end

#with_test_task {|tt| ... } ⇒ nil

Customize the test task.

is generated

Yields:

  • (tt)

    called after the defaults are set but before the test task

Yield Parameters:

  • tt (Rake::TestTask)

Returns:

  • (nil)


52
53
54
55
# File 'lib/gemma/rake_tasks/minitest_tasks.rb', line 52

def with_test_task &block
  @with_test_task = block
  nil
end