Class: Beaker::TestSuite

Inherits:
Object
  • Object
show all
Defined in:
lib/beaker/test_suite.rb

Overview

This Class is in need of some cleaning up beyond what can be quickly done. Things to keep in mind:

* Global State Change
* File Creation Relative to CWD  -- Should be a config option
* Better Method Documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, hosts, options, fail_mode = nil) ⇒ TestSuite

Returns a new instance of TestSuite.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/beaker/test_suite.rb', line 21

def initialize(name, hosts, options, fail_mode = nil)
  @logger     = options[:logger]
  @test_cases = []
  @test_files = options[name]
  @name       = name.to_s.gsub(/\s+/, '-')
  @hosts      = hosts
  @run        = false
  @options    = options
  @fail_mode  = options[:fail_mode] || fail_mode

  report_and_raise(@logger, RuntimeError.new("#{@name}: no test files found..."), "TestSuite: initialize") if @test_files.empty?

rescue => e
  report_and_raise(@logger, e, "TestSuite: initialize")
end

Instance Attribute Details

#fail_modeObject (readonly)

Returns the value of attribute fail_mode.



19
20
21
# File 'lib/beaker/test_suite.rb', line 19

def fail_mode
  @fail_mode
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/beaker/test_suite.rb', line 19

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'lib/beaker/test_suite.rb', line 19

def options
  @options
end

Instance Method Details

#errored_testsObject



111
112
113
# File 'lib/beaker/test_suite.rb', line 111

def errored_tests
  @errored_tests ||= @test_cases.select { |c| c.test_status == :error }.length
end

#fail_without_test_runObject



90
91
92
# File 'lib/beaker/test_suite.rb', line 90

def fail_without_test_run
  report_and_raise(@logger, RuntimeError.new("#{@name}: you have not run the tests yet"), "TestSuite: fail_without_test_run") unless @run
end

#failed?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/beaker/test_suite.rb', line 99

def failed?
  !success?
end

#failed_testsObject



115
116
117
# File 'lib/beaker/test_suite.rb', line 115

def failed_tests
  @failed_tests ||= @test_cases.select { |c| c.test_status == :fail }.length
end

#passed_testsObject



107
108
109
# File 'lib/beaker/test_suite.rb', line 107

def passed_tests
  @passed_tests ||= @test_cases.select { |c| c.test_status == :pass }.length
end

#pending_testsObject



123
124
125
# File 'lib/beaker/test_suite.rb', line 123

def pending_tests
  @pending_tests ||= @test_cases.select {|c| c.test_status == :pending}.length
end

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/beaker/test_suite.rb', line 37

def run
  @run = true
  @start_time = Time.now

  configure_logging 

  @test_files.each do |test_file|
    @logger.notify
    @logger.notify "Begin #{test_file}"
    start = Time.now
    test_case = TestCase.new(@hosts, @logger, options, test_file).run_test
    duration = Time.now - start
    @test_cases << test_case

    state = test_case.test_status == :skip ? 'skipp' : test_case.test_status
    msg = "#{test_file} #{state}ed in %.2f seconds" % duration.to_f
    case test_case.test_status
    when :pass
      @logger.success msg
    when :skip
      @logger.debug msg
    when :fail
      @logger.error msg
      break if fail_mode !~ /slow/ #all failure modes except slow cause us to kick out early on failure
    when :error
      @logger.warn msg
      break if fail_mode !~ /slow/ #all failure modes except slow cause us to kick out early on failure
    end
  end

  # REVISIT: This changes global state, breaking logging in any future runs
  # of the suite – or, at least, making them highly confusing for anyone who
  # has not studied the implementation in detail. --daniel 2011-03-14
  summarize
  write_junit_xml if options[:xml]

  # Allow chaining operations...
  return self
end

#run_and_raise_on_failureObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/beaker/test_suite.rb', line 77

def run_and_raise_on_failure
  begin
    run
    return self if success?
  rescue => e
    #failed during run
    report_and_raise(@logger, e, "TestSuite :run_and_raise_on_failure")
  else
    #failed during test
    report_and_raise(@logger, RuntimeError.new("Failed while running the #{name} suite"), "TestSuite: report_and_raise_on_failure")
  end
end

#skipped_testsObject



119
120
121
# File 'lib/beaker/test_suite.rb', line 119

def skipped_tests
  @skipped_tests ||= @test_cases.select { |c| c.test_status == :skip }.length
end

#success?Boolean

Returns:

  • (Boolean)


94
95
96
97
# File 'lib/beaker/test_suite.rb', line 94

def success?
  fail_without_test_run
  sum_failed == 0
end

#test_countObject



103
104
105
# File 'lib/beaker/test_suite.rb', line 103

def test_count
  @test_count ||= @test_cases.length
end