class Detroit::RSpec
The RSpec
tool is used to run project specifications written with RSpec
. Specifications are expected to found in the standard ‘spec/` directory unless otherwise specified in the tools options.
Options:
specs File glob(s) of spec files. Defaults to ['spec/**/*_spec.rb', 'spec/**/spec_*.rb']. loadpath Paths to add $LOAD_PATH. Defaults to ['lib']. live Ignore loadpath, use installed libraries instead. Default is false. require Lib(s) to require before excuting specifications. warning Whether to show warnings or not. Default is false. format Format of RSpec output. extra Additional commandl ine options for spec command.
NOTE: This tool currently shells out to the command line.
Attributes
Additional command line options for rspec.
Format of RSpec
output.
Paths to add $LOAD_PATH. Defaults to [‘lib’].
Output file, STDOUT if nil.
Scripts to require before excuting specifications.
File glob(s) of spec files. Defaults to [‘spec/*/_spec.rb’, ‘spec/*/spec_.rb’].
Whether to show warnings or not. Default is false.
Public Class Methods
# File lib/detroit-rspec.rb, line 160 def self.man_page File.dirname(__FILE__)+'/../man/detroit-rspec.5' end
Public Instance Methods
Attach test method to test assembly.
@todo Attach documentaton?
# File lib/detroit-rspec.rb, line 75 def assemble(station, options={}) case station #when :document then document when :test then run end end
# File lib/detroit-rspec.rb, line 66 def assemble?(station, options={}) case station when :test then true end end
Run all specs with documentation output.
# File lib/detroit-rspec.rb, line 96 def document run_specs('documentation') end
Run all specs.
Returns false
if any tests failed, otherwise true
.
# File lib/detroit-rspec.rb, line 88 def run run_specs end
Private Instance Methods
Extra options.
# File lib/detroit-rspec.rb, line 142 def extra_options case extra when String extra.split(/\s+/) when Array extra else [] end end
# File lib/detroit-rspec.rb, line 103 def initialize_defaults @loadpath = metadata.loadpath @specs = ['spec/**/*_spec.rb', 'spec/**/spec_*.rb'] @requires = [] @warning = false end
# File lib/detroit-rspec.rb, line 154 def initialize_requires require 'rspec/core' end
Run rspecs.
# File lib/detroit-rspec.rb, line 112 def run_specs(format=nil) format = format || self.format specs = self.specs.to_list loadpath = self.loadpath.to_list requires = self.requires.to_list files = multiglob(*specs) if files.empty? puts "No specifications." else # ruby [ruby_opts] -Ilib bin/spec examples [spec_opts] argv = [] argv << "-w" if warning argv << %[-I"#{loadpath.join(':')}"] unless loadpath.empty? argv << %[-r"#{requires.join(':')}"] unless requires.empty? argv << %[-f"#{format}"] if format argv << %[-o"#{output}"] if output argv << files argv << extra_options argv = argv.flatten trace "rspec " + argv.join(' ') success = ::RSpec::Core::Runner.run(argv) end end