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

extra[RW]

Additional command line options for rspec.

format[RW]

Format of RSpec output.

loadpath[RW]

Paths to add $LOAD_PATH. Defaults to [‘lib’].

output[RW]

Output file, STDOUT if nil.

requires[RW]

Scripts to require before excuting specifications.

specs[RW]

File glob(s) of spec files. Defaults to [‘spec/*/_spec.rb’, ‘spec/*/spec_.rb’].

warning[RW]

Whether to show warnings or not. Default is false.

Public Class Methods

man_page() click to toggle source
# File lib/detroit-rspec.rb, line 160
def self.man_page
  File.dirname(__FILE__)+'/../man/detroit-rspec.5'      
end

Public Instance Methods

assemble(station, options={}) click to toggle source

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
assemble?(station, options={}) click to toggle source
# File lib/detroit-rspec.rb, line 66
def assemble?(station, options={})
  case station
  when :test then true
  end
end
document() click to toggle source

Run all specs with documentation output.

# File lib/detroit-rspec.rb, line 96
def document
  run_specs('documentation')
end
run() click to toggle source

Run all specs.

Returns false if any tests failed, otherwise true.

# File lib/detroit-rspec.rb, line 88
def run
  run_specs
end
Also aliased as: test
test()
Alias for: run

Private Instance Methods

extra_options() click to toggle source

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
initialize_defaults() click to toggle source
# File lib/detroit-rspec.rb, line 103
def initialize_defaults
  @loadpath = metadata.loadpath

  @specs    = ['spec/**/*_spec.rb', 'spec/**/spec_*.rb']
  @requires = []
  @warning  = false
end
initialize_requires() click to toggle source
# File lib/detroit-rspec.rb, line 154
def initialize_requires
  require 'rspec/core'
end
run_specs(format=nil) click to toggle source

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