class Tiramisu::Unit

Public Class Methods

context(label, &block) click to toggle source

define a context inside current spec/context.

@param label @param &block

# File lib/tiramisu/unit.rb, line 74
def context label, &block
  return unless block
  Tiramisu.define_and_register_a_context(label, block, self)
end
hooks() click to toggle source
# File lib/tiramisu/unit.rb, line 161
def hooks
  @__tiramisu_hooks__ ||= {}
end
inherited(base) click to toggle source
# File lib/tiramisu/unit.rb, line 61
def inherited base
  base.instance_variable_set(:@__tiramisu_hooks__, Marshal.load(Marshal.dump(hooks)))
end
it(label, &block)
Alias for: test
run(test) click to toggle source
# File lib/tiramisu/unit.rb, line 178
def run test
  tests[test] || raise(StandardError, 'Undefined test %s at "%s"' % [test.inspect, __identity__])
  catch :__tiramisu_status__ do
    allocate.__run__(tests[test], hooks[:before], hooks[:around], hooks[:after])
  end
end
should(label, &block)
Alias for: test
skip(reason = nil) click to toggle source

skipping a whole spec/context

@example

spec Array do
  skip

  # code here wont be executed
end
# File lib/tiramisu/unit.rb, line 174
def skip reason = nil
  throw(:__tiramisu_skip__, Tiramisu::Skip.new(reason, caller[0]))
end
spec() click to toggle source
# File lib/tiramisu/unit.rb, line 65
def spec
  raise(NotImplementedError, 'Nested specs not supported. Please use a context instead')
end
test(label, &block) click to toggle source

define a test

@param label @param &block

# File lib/tiramisu/unit.rb, line 84
def test label, &block
  return unless block
  tests[label] = Tiramisu.identity_string(:test, label, block)
  define_method(tests[label], &block)
end
Also aliased as: it, should
tests() click to toggle source
# File lib/tiramisu/unit.rb, line 92
def tests
  @__tiramisu_tests__ ||= {}
end

Public Instance Methods

__run__(test, before, around, after) click to toggle source
# File lib/tiramisu/unit.rb, line 34
def __run__ test, before, around, after
  __send__(before) if before
  if around
    __send__(around, proc {__send__(test)})
  else
    __send__(test)
  end
  __send__(after) if after
  __assertions__.each(&:__validate_expectations__)
  __objects__.each_key {|o| Tiramisu::Expectation.restore_object_status(o[:returned])}
  :__tiramisu_passed__
rescue Exception => e
  throw(:__tiramisu_status__, e)
end
skip(reason = nil) click to toggle source

stop executing current test and mark it as skipped

@example

test :something do
  skip "recheck this after fixing X"
  assert(x) == y # this wont run
end
# File lib/tiramisu/unit.rb, line 30
def skip reason = nil
  throw(:__tiramisu_status__, Tiramisu::Skip.new(reason, caller[0]))
end

Private Instance Methods

__assertions__() click to toggle source
# File lib/tiramisu/unit.rb, line 54
def __assertions__
  @__assertions__ ||= []
end
__objects__() click to toggle source
# File lib/tiramisu/unit.rb, line 50
def __objects__
  @__objects__ ||= {}
end