Class: Toys::Templates::Rspec

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

Overview

A template for tools that run rspec

Constant Summary collapse

DEFAULT_GEM_VERSION_REQUIREMENTS =

Default version requirements for the rspec gem.

Returns:

  • (Array<String>)
["~> 3.1"].freeze
DEFAULT_TOOL_NAME =

Default tool name

Returns:

  • (String)
"spec"
DEFAULT_LIBS =

Default set of library paths

Returns:

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

Default order type

Returns:

  • (String)
"defined"
DEFAULT_FORMAT =

Default format code

Returns:

  • (String)
"p"
DEFAULT_PATTERN =

Default spec file glob

Returns:

  • (String)
"spec/**/*_spec.rb"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Toys::Template

create

Constructor Details

#initialize(name: nil, gem_version: nil, libs: nil, options: nil, order: nil, format: nil, out: nil, backtrace: false, pattern: nil, warnings: true, bundler: false, context_directory: nil) ⇒ Rspec

Create the template settings for the RSpec template.

Parameters:

  • name (String) (defaults to: nil)

    Name of the tool to create. Defaults to DEFAULT_TOOL_NAME.

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

    Version requirements for the rspec gem. Defaults to DEFAULT_GEM_VERSION_REQUIREMENTS.

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

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

  • options (String) (defaults to: nil)

    The path to a custom options file, if any.

  • order (String) (defaults to: nil)

    The order in which to run examples. Default is DEFAULT_ORDER.

  • format (String) (defaults to: nil)

    The formatter code. Default is DEFAULT_FORMAT.

  • out (String) (defaults to: nil)

    Write output to a file instead of stdout.

  • backtrace (Boolean) (defaults to: false)

    Enable full backtrace (default is false).

  • pattern (String) (defaults to: nil)

    A glob indicating the spec files to load. Defaults to DEFAULT_PATTERN.

  • warnings (Boolean) (defaults to: true)

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

  • bundler (Boolean, Hash) (defaults to: false)

    If false (the default), bundler is not enabled for this tool. If true or a Hash of options, bundler is enabled. See the documentation for the bundler mixin for information on available options.

  • context_directory (String) (defaults to: nil)

    A custom context directory to use when executing this tool.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/toys/templates/rspec.rb', line 74

def initialize(name: nil,
               gem_version: nil,
               libs: nil,
               options: nil,
               order: nil,
               format: nil,
               out: nil,
               backtrace: false,
               pattern: nil,
               warnings: true,
               bundler: false,
               context_directory: nil)
  @name = name
  @gem_version = gem_version
  @libs = libs
  @options = options
  @order = order
  @format = format
  @out = out
  @backtrace = backtrace
  @pattern = pattern
  @warnings = warnings
  @bundler = bundler
  @context_directory = context_directory
end

Instance Attribute Details

#backtrace=(value) ⇒ Boolean

Whether to enable full backtraces.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


169
170
171
# File 'lib/toys/templates/rspec.rb', line 169

def backtrace=(value)
  @backtrace = value
end

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


207
208
209
# File 'lib/toys/templates/rspec.rb', line 207

def bundler=(value)
  @bundler = value
end

#context_directory=(value) ⇒ String

Custom context directory for this tool.

Parameters:

  • value (String)

Returns:

  • (String)


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

def context_directory=(value)
  @context_directory = value
end

#format=(value) ⇒ String?

The formatter code. If set to nil, defaults to DEFAULT_FORMAT.

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


152
153
154
# File 'lib/toys/templates/rspec.rb', line 152

def format=(value)
  @format = value
end

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

Version requirements for the rspec gem. If set to nil, uses the bundled version if bundler is enabled, or defaults to DEFAULT_GEM_VERSION_REQUIREMENTS if bundler is not enabled.

Parameters:

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

Returns:

  • (String, Array<String>, nil)


117
118
119
# File 'lib/toys/templates/rspec.rb', line 117

def gem_version=(value)
  @gem_version = value
end

#libs=(value) ⇒ Array<String>?

An array of directories to add to the Ruby require path. If set to nil, defaults to DEFAULT_LIBS.

Parameters:

  • value (Array<String>, nil)

Returns:

  • (Array<String>, nil)


126
127
128
# File 'lib/toys/templates/rspec.rb', line 126

def libs=(value)
  @libs = value
end

#name=(value) ⇒ String

Name of the tool to create.

Parameters:

  • value (String)

Returns:

  • (String)


106
107
108
# File 'lib/toys/templates/rspec.rb', line 106

def name=(value)
  @name = value
end

#options=(value) ⇒ String?

Path to the custom options file, or nil for none.

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


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

def options=(value)
  @options = value
end

#order=(value) ⇒ String?

The order in which to run examples. If set to nil, defaults to DEFAULT_ORDER.

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


143
144
145
# File 'lib/toys/templates/rspec.rb', line 143

def order=(value)
  @order = value
end

#out=(value) ⇒ String?

Path to a file to write output to. If set to nil, writes output to standard out.

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


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

def out=(value)
  @out = value
end

#pattern=(value) ⇒ String?

A glob indicating the spec files to load. If set to nil, defaults to DEFAULT_PATTERN.

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


178
179
180
# File 'lib/toys/templates/rspec.rb', line 178

def pattern=(value)
  @pattern = value
end

#warnings=(value) ⇒ Boolean

Whether to run with Ruby warnings.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


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

def warnings=(value)
  @warnings = value
end

Instance Method Details

#use_bundler(**opts) ⇒ self

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


219
220
221
222
# File 'lib/toys/templates/rspec.rb', line 219

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