Class: Toys::Templates::Rspec
- Inherits:
-
Object
- Object
- Toys::Templates::Rspec
- 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 gem names.
{ "rspec" => ["~> 3.1"].freeze, }.freeze
- DEFAULT_TOOL_NAME =
Default tool name
"spec"- DEFAULT_LIBS =
Default set of library paths
["lib"].freeze
- DEFAULT_ORDER =
Default order type
"defined"- DEFAULT_FORMAT =
Default format code
"p"- DEFAULT_PATTERN =
Default spec file glob
"spec/**/*_spec.rb"
Instance Attribute Summary collapse
-
#backtrace ⇒ boolean
writeonly
Whether to enable full backtraces.
-
#bundler ⇒ boolean, Hash
writeonly
Set the bundler state and options for this tool.
-
#context_directory ⇒ String
writeonly
Custom context directory for this tool.
-
#format ⇒ String?
writeonly
The formatter code.
-
#libs ⇒ Array<String>?
writeonly
An array of directories to add to the Ruby require path.
-
#name ⇒ String
writeonly
Name of the tool to create.
-
#options ⇒ String?
writeonly
Path to the custom options file, or
nilfor none. -
#order ⇒ String?
writeonly
The order in which to run examples.
-
#out ⇒ String?
writeonly
Path to a file to write output to.
-
#pattern ⇒ String?
writeonly
A glob indicating the spec files to load.
-
#warnings ⇒ boolean
writeonly
Whether to run with Ruby warnings.
Instance Method Summary collapse
-
#initialize(name: nil, rspec: nil, gems: nil, libs: nil, options: nil, order: nil, format: nil, out: nil, backtrace: false, pattern: nil, warnings: true, bundler: false, context_directory: nil) ⇒ Rspec
constructor
Create the template settings for the RSpec template.
-
#rspec=(value) ⇒ Object
Version requirements for the rspec gem.
-
#update_gems(gems) ⇒ self
Update the gems and version requirements that are used if bundler is not enabled.
-
#use_bundler(**opts) ⇒ self
Activate bundler for this tool.
Methods included from Toys::Template
Constructor Details
#initialize(name: nil, rspec: nil, gems: 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.
Note that arguments related to gem and bundler settings are defaults that can be overridden by command line arguments.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/toys/templates/rspec.rb', line 90 def initialize(name: nil, rspec: nil, gems: nil, libs: nil, options: nil, order: nil, format: nil, out: nil, backtrace: false, pattern: nil, warnings: true, bundler: false, context_directory: nil) @name = name @libs = libs @options = @order = order @format = format @out = out @backtrace = backtrace @pattern = pattern @warnings = warnings @bundler = bundler @context_directory = context_directory @gem_dependencies = {} update_version_spec("rspec", rspec) update_gems(gems) if gems end |
Instance Attribute Details
#backtrace=(value) ⇒ boolean
Whether to enable full backtraces.
206 207 208 |
# File 'lib/toys/templates/rspec.rb', line 206 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.
244 245 246 |
# File 'lib/toys/templates/rspec.rb', line 244 def bundler=(value) @bundler = value end |
#context_directory=(value) ⇒ String
Custom context directory for this tool.
231 232 233 |
# File 'lib/toys/templates/rspec.rb', line 231 def context_directory=(value) @context_directory = value end |
#format=(value) ⇒ String?
The formatter code.
If set to nil, defaults to DEFAULT_FORMAT.
189 190 191 |
# File 'lib/toys/templates/rspec.rb', line 189 def format=(value) @format = 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.
163 164 165 |
# File 'lib/toys/templates/rspec.rb', line 163 def libs=(value) @libs = value end |
#name=(value) ⇒ String
Name of the tool to create.
125 126 127 |
# File 'lib/toys/templates/rspec.rb', line 125 def name=(value) @name = value end |
#options=(value) ⇒ String?
Path to the custom options file, or nil for none.
171 172 173 |
# File 'lib/toys/templates/rspec.rb', line 171 def (value) @options = value end |
#order=(value) ⇒ String?
The order in which to run examples.
If set to nil, defaults to DEFAULT_ORDER.
180 181 182 |
# File 'lib/toys/templates/rspec.rb', line 180 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.
198 199 200 |
# File 'lib/toys/templates/rspec.rb', line 198 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.
215 216 217 |
# File 'lib/toys/templates/rspec.rb', line 215 def pattern=(value) @pattern = value end |
#warnings=(value) ⇒ boolean
Whether to run with Ruby warnings.
223 224 225 |
# File 'lib/toys/templates/rspec.rb', line 223 def warnings=(value) @warnings = value end |
Instance Method Details
#rspec=(value) ⇒ Object
Version requirements for the rspec gem. Used if bundler is not used.
If set to true or nil, a default version requirement is used.
152 153 154 |
# File 'lib/toys/templates/rspec.rb', line 152 def rspec=(value) update_version_spec("rspec", value) end |
#update_gems(gems) ⇒ self
Update the gems and version requirements that are used if bundler is not enabled.
139 140 141 142 143 144 |
# File 'lib/toys/templates/rspec.rb', line 139 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
Activate bundler for this tool.
See the documentation for the bundler mixin for information on the options that can be passed.
256 257 258 259 |
# File 'lib/toys/templates/rspec.rb', line 256 def use_bundler(**opts) @bundler = opts self end |