Module: Sapphire::Testing::Executable

Included in:
And, Background, Finally, Given, Then, When
Defined in:
lib/sapphire/Testing/Executable.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sapphire/Testing/Executable.rb', line 14

def execute()
  start = Time.now
  Report do |x| x.TestStarted(self) end
  begin
    if(self.value.is_a? Pending)
      result = ResultTree.new(self.text, TestResult.new("pending", self, "Pending", "", Time.now - start))
      self.AddResult(result)
      Report do |x| x.TestPending(result) end
      return
    end
    self.block.call
    result = ResultTree.new(self.text, TestResult.new("pass", self, "Success", "", Time.now - start))
    self.AddResult(result)
    Report do |x| x.TestPassed(result) end
  rescue => msg
    stack = msg.backtrace
    message = msg.messages if (msg.is_a? ExpectationException)
    message ||= msg.message
    if(self.value.is_a? Broken)
      result = ResultTree.new(self.text, TestResult.new("broken", self, message, stack, Time.now - start))
      self.AddResult(result)
      Report do |x| x.TestBroken(result) end
    else
      result = ResultTree.new(self.text, TestResult.new("fail", self, message, stack, Time.now - start))
      self.AddResult(result)
      Report do |x| x.TestFailed(result) end
    end
  end
end

#pendObject



5
6
7
8
9
10
11
12
# File 'lib/sapphire/Testing/Executable.rb', line 5

def pend()
  start = Time.now
  Report do |x| x.TestStarted(self) end

  result = ResultTree.new(self.text, TestResult.new("pending", self, "Pending", "", Time.now - start))
  self.AddResult(result)
  Report do |x| x.TestPending(result) end
end

#Report(&block) ⇒ Object



44
45
46
47
48
# File 'lib/sapphire/Testing/Executable.rb', line 44

def Report(&block)
  $instances.each do |reporter|
    block.call reporter
  end
end