Class: Toys::Templates::Minitest

Inherits:
Object
  • Object
show all
Includes:
Toys::Template
Defined in:
lib/toys/templates/minitest.rb

Overview

A template for tools that run minitest

Constant Summary collapse

DEFAULT_GEM_VERSION_REQUIREMENTS =

Default version requirements for gem names.

Returns:

  • (Hash{String=>Array<String>})
{
  "minitest" => [">= 5.0", "< 7"].freeze,
  "minitest-mock" => ["~> 5.27"].freeze,
  "minitest-focus" => ["~> 1.4", ">= 1.4.1"].freeze,
  "minitest-rg" => ["~> 5.4"].freeze,
}.freeze
DEFAULT_TOOL_NAME =

Default tool name

Returns:

  • (String)
"test"
DEFAULT_LIBS =

Default set of library paths

Returns:

  • (Array<String>)
["lib"].freeze
DEFAULT_FILES =

Default set of test file globs

Returns:

  • (Array<String>)
["test/**/test_*.rb", "test/**/*_test.rb"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Toys::Template

create

Constructor Details

#initialize(name: nil, minitest: nil, minitest_mock: nil, minitest_focus: nil, minitest_rg: nil, gems: nil, libs: nil, files: nil, seed: nil, verbose: false, warnings: true, bundler: false, mt_compat: nil, context_directory: nil) ⇒ Minitest

Create the template settings for the Minitest template.

Note that arguments related to gem and bundler settings are defaults that can be overridden by command line arguments.

Parameters:

  • name (String) (defaults to: nil) —

    Name of the tool to create. Defaults to DEFAULT_TOOL_NAME.

  • minitest (String, Array<String>) (defaults to: nil) —

    Version requirements for the "minitest" gem, used if bundler is not enabled. Optional. If not provided, defaults to the value given in DEFAULT_GEM_VERSION_REQUIREMENTS.

  • minitest_mock (String, Array<String>, true) (defaults to: nil) —

    Include the "minitest-mock" gem with the given version requirements. Used if bundler is not enabled. If true is passed, the value in DEFAULT_GEM_VERSION_REQUIREMENTS is used.

  • minitest_focus (String, Array<String>, true) (defaults to: nil) —

    Include the "minitest-focus" gem with the given version requirements. Used if bundler is not enabled. If true is passed, the value in DEFAULT_GEM_VERSION_REQUIREMENTS is used.

  • minitest_rg (String, Array<String>, true) (defaults to: nil) —

    Include the "minitest-rg" gem with the given version requirements. Used if bundler is not enabled. If true is passed, the value in DEFAULT_GEM_VERSION_REQUIREMENTS is used.

  • gems (Hash{String=>String|Array<String>|true}) (defaults to: nil) —

    Include the given gems with the given version requirements. Used if bundler is not enabled. If the version requirement is set to true, then a the default in DEFAULT_GEM_VERSION_REQUIREMENTS is used. If there is no default available, then no particular version requirements are imposed.

  • libs (Array<String>) (defaults to: nil) —

    An array of library paths to add to the ruby require path. Defaults to DEFAULT_LIBS.

  • files (Array<String>) (defaults to: nil) —

    An array of globs indicating the test files to load. Defaults to DEFAULT_FILES.

  • seed (Integer) (defaults to: nil) —

    The random seed, if any. Optional.

  • verbose (boolean) (defaults to: false) —

    Whether to produce verbose output. Defaults to false.

  • warnings (boolean) (defaults to: true) —

    If true, runs tests with Ruby warnings. Defaults to true.

  • bundler (boolean, Hash) (defaults to: false) —

    If false (the default), bundler is not used unless enabled via command line argument. If true or a Hash of options, bundler is enabled by default unless disabled via a command line argument. See the documentation for the bundler mixin for information on available options. Note that any :setup option is ignored; the bundle, if enabled, is always installed and set up at the start of the tool execution.

  • mt_compat (boolean) (defaults to: nil) —

    If set to true or false, sets the MT_COMPAT environment variable accordingly. This may be required for certain older Minitest plugins. Optional. If not present, keeps any current setting.

  • context_directory (String) (defaults to: nil) —

    A custom context directory to use when executing this tool.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/toys/templates/minitest.rb', line 94

def initialize(name: nil,
               minitest: nil,
               minitest_mock: nil,
               minitest_focus: nil,
               minitest_rg: nil,
               gems: nil,
               libs: nil,
               files: nil,
               seed: nil,
               verbose: false,
               warnings: true,
               bundler: false,
               mt_compat: nil,
               context_directory: nil)
  @name = name
  @libs = libs
  @files = files
  @seed = seed
  @verbose = verbose
  @warnings = warnings
  @bundler = bundler
  @mt_compat = mt_compat
  @context_directory = context_directory
  @gem_dependencies = {}
  update_version_spec("minitest", minitest)
  update_version_spec("minitest-mock", minitest_mock)
  update_version_spec("minitest-focus", minitest_focus)
  update_version_spec("minitest-rg", minitest_rg)
  update_gems(gems) if gems
end

Instance Attribute Details

#bundler=(value) ⇒ boolean, Hash (writeonly)

Set the bundler state and options for this tool.

Pass false to disable bundler. Pass true or a hash of options to enable bundler. See the documentation for the bundler mixin for information on the options that can be passed.

Parameters:

  • value (boolean, Hash)

Returns:

  • (boolean, Hash)


259
260
261
# File 'lib/toys/templates/minitest.rb', line 259

def bundler=(value)
  @bundler = value
end

#context_directory=(value) ⇒ String

Custom context directory for this tool.

Parameters:

  • value (String)

Returns:

  • (String)


246
247
248
# File 'lib/toys/templates/minitest.rb', line 246

def context_directory=(value)
  @context_directory = value
end

#files=(value) ⇒ String, ...

An array of globs indicating the test files to load. If set to nil, defaults to DEFAULT_FILES.

Parameters:

  • value (String, Array<String>, nil)

Returns:

  • (String, Array<String>, nil)


214
215
216
# File 'lib/toys/templates/minitest.rb', line 214

def files=(value)
  @files = value
end

#libs=(value) ⇒ String, ...

An array of library paths to add to the ruby require path. If set to nil, defaults to DEFAULT_LIBS.

Parameters:

  • value (String, Array<String>, nil)

Returns:

  • (String, Array<String>, nil)


205
206
207
# File 'lib/toys/templates/minitest.rb', line 205

def libs=(value)
  @libs = value
end

#mt_compat=(value) ⇒ true, ...

Adjust the MT_COMPAT environment variable when running tests. This setting may be necessary for certain older Minitest plugins.

Pass true to enable compat mode, false to disable it, or nil to use any ambient setting from the current environment.

Parameters:

  • value (true, false, nil)

Returns:

  • (true, false, nil)


271
272
273
# File 'lib/toys/templates/minitest.rb', line 271

def mt_compat=(value)
  @mt_compat = value
end

#name=(value) ⇒ String

Name of the tool to create.

Parameters:

  • value (String)

Returns:

  • (String)


131
132
133
# File 'lib/toys/templates/minitest.rb', line 131

def name=(value)
  @name = value
end

#seed=(value) ⇒ Integer?

The random seed, or nil if not specified.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer, nil)


222
223
224
# File 'lib/toys/templates/minitest.rb', line 222

def seed=(value)
  @seed = value
end

#verbose=(value) ⇒ boolean

Whether to produce verbose output.

Parameters:

  • value (boolean)

Returns:

  • (boolean)


230
231
232
# File 'lib/toys/templates/minitest.rb', line 230

def verbose=(value)
  @verbose = value
end

#warnings=(value) ⇒ boolean

Whether to run tests with Ruby warnings.

Parameters:

  • value (boolean)

Returns:

  • (boolean)


238
239
240
# File 'lib/toys/templates/minitest.rb', line 238

def warnings=(value)
  @warnings = value
end

Instance Method Details

#minitest=(value) ⇒ Object

Version requirements for the minitest gem. Used if bundler is not used. If set to true or nil, a default version requirement is used.

Parameters:

  • value (String, Array<String>, true, nil)


158
159
160
# File 'lib/toys/templates/minitest.rb', line 158

def minitest=(value)
  update_version_spec("minitest", value)
end

#minitest_focus=(value) ⇒ Object

Version requirements for the minitest-focus gem. Used if bundler is not used. If set to true, a default version requirement is used. If set to nil, minitest-focus is removed from the gem dependencies.

Parameters:

  • value (String, Array<String>, true, nil)


182
183
184
# File 'lib/toys/templates/minitest.rb', line 182

def minitest_focus=(value)
  update_version_spec("minitest-focus", value)
end

#minitest_mock=(value) ⇒ Object

Version requirements for the minitest-mock gem. Used if bundler is not used. If set to true, a default version requirement is used. If set to nil, minitest-mock is removed from the gem dependencies.

Parameters:

  • value (String, Array<String>, true, nil)


170
171
172
# File 'lib/toys/templates/minitest.rb', line 170

def minitest_mock=(value)
  update_version_spec("minitest-mock", value)
end

#minitest_rg=(value) ⇒ Object

Version requirements for the minitest-rg gem. Used if bundler is not used. If set to true, a default version requirement is used. If set to nil, minitest-rg is removed from the gem dependencies.

Parameters:

  • value (String, Array<String>, true, nil)


194
195
196
# File 'lib/toys/templates/minitest.rb', line 194

def minitest_rg=(value)
  update_version_spec("minitest-rg", value)
end

#update_gems(gems) ⇒ self

Update the gems and version requirements that are used if bundler is not enabled.

Parameters:

  • gems (Hash{String=>String|Array<String>|true|false|nil}) —

    A mapping from gem name to either the version requirements, true to use a default, or false or nil to remove the gem from the list. (Note that it is not possible to remove the minitest gem, and setting it to nil will simply restore the default version requirements.)

Returns:

  • (self)


145
146
147
148
149
150
# File 'lib/toys/templates/minitest.rb', line 145

def update_gems(gems)
  gems.each do |gem_name, version_requirements|
    update_version_spec(gem_name, version_requirements)
  end
  self
end

#use_bundler(**opts) ⇒ self

Use bundler for this tool.

See the documentation for the bundler mixin for information on the options that can be passed.

Parameters:

  • opts (keywords) —

    Options for bundler

Returns:

  • (self)


283
284
285
286
# File 'lib/toys/templates/minitest.rb', line 283

def use_bundler(**opts)
  @bundler = opts
  self
end