class TOTS::Spec

The spec unit

Copyright (C) 2013 Nikolay Nemshilov

Public Class Methods

context(*args, &block) click to toggle source

alias for `describe`

# File lib/tots/spec.rb, line 28
def self.context(*args, &block)
  describe(*args, &block)
end
describe(*args, &block) click to toggle source

Sub-describe blocks catcher

# File lib/tots/spec.rb, line 21
def self.describe(*args, &block)
  specs << Class.new(TOTS::Spec, &block)
end
it(*args,&block) click to toggle source

The basic `it` thingy

“`ruby describe Smth do

it "must do stuff" do
end

end “`

# File lib/tots/spec.rb, line 42
def self.it(*args,&block)
  if args.size == 0
    self
  else
    tests << TOTS::Test.new(args + [block])
  end
end
run() click to toggle source

Runs the spec

# File lib/tots/spec.rb, line 68
def self.run
  TOTS::Printer.testing self

  suite = new

  tests.each do |test|
    TOTS::Printer.running test.name

    begin
      test.run(suite)

      TOTS::Printer.passed

    rescue TOTS::Test::Skip => e
      TOTS::Printer.skipped

    rescue TOTS::Test::Fail => e
      TOTS::Printer.failed(e)
    end
  end

  specs.each(&:run)
end
skip(*args, &block) click to toggle source

Quick, skip marking

“`ruby describe Smth do

it.skip "this test" do
  this_code.will_be(:skipped)
end

end “`

# File lib/tots/spec.rb, line 61
def self.skip(*args, &block)
  it *args # skipping the block
end
specs() click to toggle source
# File lib/tots/spec.rb, line 14
def self.specs
  @specs ||= []
end
tests() click to toggle source

the tests stash

# File lib/tots/spec.rb, line 10
def self.tests
  @tests ||= []
end