Class: GUnit::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/gunit/context.rb

Overview

Context instance has message, setups, exercises, teardowns, and parent (another Context)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &blk) ⇒ Context

Context.new(“my message”) Context.new(“my message”) do

setup { @foo = "bar" }
verify { true }

end Context.new do

setup { @foo = "bar" }
verify { true }

end



15
16
17
18
19
20
# File 'lib/gunit/context.rb', line 15

def initialize(*args, &blk)
  self.message    = args[0] || ''
  self.setups     = []
  self.teardowns  = []
  self.task = blk if blk
end

Instance Attribute Details

#exerciseObject

Returns the value of attribute exercise.



4
5
6
# File 'lib/gunit/context.rb', line 4

def exercise
  @exercise
end

#messageObject

Returns the value of attribute message.



4
5
6
# File 'lib/gunit/context.rb', line 4

def message
  @message
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/gunit/context.rb', line 4

def parent
  @parent
end

#setupsObject

Returns the value of attribute setups.



4
5
6
# File 'lib/gunit/context.rb', line 4

def setups
  @setups
end

#taskObject

Returns the value of attribute task.



4
5
6
# File 'lib/gunit/context.rb', line 4

def task
  @task
end

#teardownsObject

Returns the value of attribute teardowns.



4
5
6
# File 'lib/gunit/context.rb', line 4

def teardowns
  @teardowns
end

Instance Method Details

#all_messageObject



30
31
32
33
34
# File 'lib/gunit/context.rb', line 30

def all_message
  parent_message = self.parent.all_message if self.parent
  parent_message = nil if parent_message == ''
  [parent_message, @message].compact.join(' ')
end

#all_setupsObject



36
37
38
# File 'lib/gunit/context.rb', line 36

def all_setups
  (self.parent ? self.parent.all_setups : []) + @setups
end

#all_teardownsObject



40
41
42
# File 'lib/gunit/context.rb', line 40

def all_teardowns
  (self.parent ? self.parent.all_teardowns : []) + @teardowns
end

#run(binding = self) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/gunit/context.rb', line 22

def run(binding=self)
  if @task.is_a?(Proc)
    bound_task = @task.bind(binding)
    bound_task.call
  end
  return true
end