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)


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

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>)


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

def files
  @files
end

#task_nameSymbol

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

Returns:

  • (Symbol)


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

def task_name
  @task_name
end

Instance Method Details

#create_rake_tasksnil

Internal method; see Plugin#create_rake_tasks.

Returns:

  • (nil)


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

def create_rake_tasks
  unless files.empty?
    require 'rake/testtask'
    Rake::TestTask.new(task_name) do |tt|
      tt.libs = gemspec.require_paths.dup
      tt.libs << 'test'
      tt.test_files = 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)


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

def with_test_task(&block)
  @with_test_task = block
  nil
end