Module: Tunit::Spec::DSL

Included in:
Tunit::Spec
Defined in:
lib/tunit/spec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/tunit/spec.rb', line 24

def name
  @name
end

Instance Method Details

#after(&block) ⇒ Object



32
33
34
35
36
# File 'lib/tunit/spec.rb', line 32

def after &block
  define_method :teardown do
    self.instance_eval(&block)
  end
end

#before(&block) ⇒ Object



26
27
28
29
30
# File 'lib/tunit/spec.rb', line 26

def before &block
  define_method :setup do
    self.instance_eval(&block)
  end
end

#childrenObject



52
53
54
# File 'lib/tunit/spec.rb', line 52

def children
  @children ||= []
end

#create(name) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/tunit/spec.rb', line 56

def create name
  klass = Class.new(self) {
    @name = name

    remove_test_methods!
  }

  children << klass

  klass
end

#it(desc, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tunit/spec.rb', line 38

def it desc, &block
  block ||= -> { skip "(no tests defined)" }

  @specs ||= 0
  @specs += 1

  test_name = desc.gsub " ", "_"
  name      = "test_%04d_%s" % [ @specs, test_name ]

  define_method name, &block

  name
end

#remove_test_methods!Object



68
69
70
71
72
# File 'lib/tunit/spec.rb', line 68

def remove_test_methods!
  self.runnable_methods.map { |test|
    self.send :undef_method, test
  }
end