Class: Beaker::TestSuite
- Inherits:
-
Object
- Object
- Beaker::TestSuite
- 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
-
#fail_mode ⇒ Object
readonly
Returns the value of attribute fail_mode.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #errored_tests ⇒ Object
- #fail_without_test_run ⇒ Object
- #failed? ⇒ Boolean
- #failed_tests ⇒ Object
-
#initialize(name, hosts, options, fail_mode = nil) ⇒ TestSuite
constructor
A new instance of TestSuite.
- #passed_tests ⇒ Object
- #pending_tests ⇒ Object
- #run ⇒ Object
- #run_and_raise_on_failure ⇒ Object
- #skipped_tests ⇒ Object
- #success? ⇒ Boolean
- #test_count ⇒ Object
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, , fail_mode = nil) @logger = [:logger] @test_cases = [] @test_files = [name] @name = name.to_s.gsub(/\s+/, '-') @hosts = hosts @run = false @options = @fail_mode = [: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_mode ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/beaker/test_suite.rb', line 19 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/beaker/test_suite.rb', line 19 def @options end |
Instance Method Details
#errored_tests ⇒ Object
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_run ⇒ Object
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
99 100 101 |
# File 'lib/beaker/test_suite.rb', line 99 def failed? !success? end |
#failed_tests ⇒ Object
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_tests ⇒ Object
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_tests ⇒ Object
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 |
#run ⇒ Object
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, , 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 [:xml] # Allow chaining operations... return self end |
#run_and_raise_on_failure ⇒ Object
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_tests ⇒ Object
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
94 95 96 97 |
# File 'lib/beaker/test_suite.rb', line 94 def success? fail_without_test_run sum_failed == 0 end |
#test_count ⇒ Object
103 104 105 |
# File 'lib/beaker/test_suite.rb', line 103 def test_count @test_count ||= @test_cases.length end |