Class: Testowl::Tester

Inherits:
Object
  • Object
show all
Defined in:
lib/testowl/tester.rb

Instance Method Summary collapse

Constructor Details

#initialize(runner, reason) ⇒ Tester

Returns a new instance of Tester.



4
5
6
7
8
# File 'lib/testowl/tester.rb', line 4

def initialize(runner, reason)
  @runner = runner
  @reason = reason
  @files_list = []
end

Instance Method Details

#add(files) ⇒ Object



10
11
12
13
# File 'lib/testowl/tester.rb', line 10

def add(files)
  array = [files].flatten
  @files_list << array unless array.empty?
end

#identifierObject



15
16
17
# File 'lib/testowl/tester.rb', line 15

def identifier
  Digest::MD5.hexdigest @files_list.flatten.join
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/testowl/tester.rb', line 19

def run
  test_count = 0
  fail_count = 0
  seconds = 0
  files_run = []
  begin
    @files_list.each do |files|
      puts "Running #{files.inspect}"
      files_run += files
      result = @runner.run(files)
      test_count += result[0]
      fail_count += result[1]
      seconds += result[2]
      break if fail_count > 0
    end
    if @files_list.empty?
      puts "No tests found"
    elsif test_count == 0
      Growl.grr "Empty Test", "No tests run", seconds, :error, files_run, @reason, identifier
      return false
    elsif fail_count > 0
      Growl.grr "Fail", "#{fail_count} out of #{test_count} test#{'s' if test_count > 1} failed :(", seconds, :failed, files_run, @reason, identifier
      return false
    else
      Growl.grr "Pass", "All #{test_count} example#{'s' if test_count > 1} passed :)", seconds, :success, files_run, @reason, identifier
      return true
    end
  rescue => exc
    Growl.grr "Exception", exc.message, nil, :error, files_run, @reason, identifier
  end
end