Class: Appetizer::Test

Inherits:
MiniTest::Unit::TestCase
  • Object
show all
Defined in:
lib/appetizer/test.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setup(&block) ⇒ Object



15
16
17
# File 'lib/appetizer/test.rb', line 15

def self.setup &block
  setups << block
end

.setupsObject



19
20
21
22
23
24
# File 'lib/appetizer/test.rb', line 19

def self.setups
  @setups ||= (ancestors - [self]).
    map { |a| a.respond_to?(:setups) && a.setups }.
    select { |s| s }.
    compact.flatten.reverse
end

.teardown(&block) ⇒ Object



26
27
28
# File 'lib/appetizer/test.rb', line 26

def self.teardown &block
  teardowns.unshift block
end

.teardownsObject



30
31
32
33
34
35
# File 'lib/appetizer/test.rb', line 30

def self.teardowns
  @teardowns ||= (ancestors - [self]).
    map { |a| a.respond_to?(:teardowns) && a.teardowns }.
    select { |t| t}.
    compact.flatten
end

.test(name, &block) ⇒ Object



37
38
39
# File 'lib/appetizer/test.rb', line 37

def self.test name, &block
  define_method "test #{name}", &block
end

Instance Method Details

#setupObject



7
8
9
# File 'lib/appetizer/test.rb', line 7

def setup
  self.class.setups.each { |s| instance_eval(&s) }
end

#teardownObject



11
12
13
# File 'lib/appetizer/test.rb', line 11

def teardown
  self.class.teardowns.each { |t| instance_eval(&t) }
end