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, gem_version: 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.

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

    Deprecated alias for the minitest argument.

  • 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.



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
124
125
126
# File 'lib/toys/templates/minitest.rb', line 96

def initialize(name: nil,
               minitest: nil,
               minitest_mock: nil,
               minitest_focus: nil,
               minitest_rg: nil,
               gems: nil,
               gem_version: 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 || gem_version)
  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)


263
264
265
# File 'lib/toys/templates/minitest.rb', line 263

def bundler=(value)
  @bundler = value
end

#context_directory=(value) ⇒ String

Custom context directory for this tool.

Parameters:

  • value (String)

Returns:

  • (String)


250
251
252
# File 'lib/toys/templates/minitest.rb', line 250

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)


218
219
220
# File 'lib/toys/templates/minitest.rb', line 218

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)


209
210
211
# File 'lib/toys/templates/minitest.rb', line 209

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)


275
276
277
# File 'lib/toys/templates/minitest.rb', line 275

def mt_compat=(value)
  @mt_compat = value
end

#name=(value) ⇒ String

Name of the tool to create.

Parameters:

  • value (String)

Returns:

  • (String)


134
135
136
# File 'lib/toys/templates/minitest.rb', line 134

def name=(value)
  @name = value
end

#seed=(value) ⇒ Integer?

The random seed, or nil if not specified.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer, nil)


226
227
228
# File 'lib/toys/templates/minitest.rb', line 226

def seed=(value)
  @seed = value
end

#verbose=(value) ⇒ boolean

Whether to produce verbose output.

Parameters:

  • value (boolean)

Returns:

  • (boolean)


234
235
236
# File 'lib/toys/templates/minitest.rb', line 234

def verbose=(value)
  @verbose = value
end

#warnings=(value) ⇒ boolean

Whether to run tests with Ruby warnings.

Parameters:

  • value (boolean)

Returns:

  • (boolean)


242
243
244
# File 'lib/toys/templates/minitest.rb', line 242

def warnings=(value)
  @warnings = value
end

Instance Method Details

#minitest=(value) ⇒ Object Also known as: gem_version=

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)


161
162
163
# File 'lib/toys/templates/minitest.rb', line 161

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)


186
187
188
# File 'lib/toys/templates/minitest.rb', line 186

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)


174
175
176
# File 'lib/toys/templates/minitest.rb', line 174

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)


198
199
200
# File 'lib/toys/templates/minitest.rb', line 198

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)


148
149
150
151
152
153
# File 'lib/toys/templates/minitest.rb', line 148

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)


287
288
289
290
# File 'lib/toys/templates/minitest.rb', line 287

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