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 36 |
# 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? @test_files = @test_files.sort 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
112 113 114 |
# File 'lib/beaker/test_suite.rb', line 112 def errored_tests @errored_tests ||= @test_cases.select { |c| c.test_status == :error }.length end |
#fail_without_test_run ⇒ Object
91 92 93 |
# File 'lib/beaker/test_suite.rb', line 91 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
100 101 102 |
# File 'lib/beaker/test_suite.rb', line 100 def failed? !success? end |
#failed_tests ⇒ Object
116 117 118 |
# File 'lib/beaker/test_suite.rb', line 116 def failed_tests @failed_tests ||= @test_cases.select { |c| c.test_status == :fail }.length end |
#passed_tests ⇒ Object
108 109 110 |
# File 'lib/beaker/test_suite.rb', line 108 def passed_tests @passed_tests ||= @test_cases.select { |c| c.test_status == :pass }.length end |
#pending_tests ⇒ Object
124 125 126 |
# File 'lib/beaker/test_suite.rb', line 124 def pending_tests @pending_tests ||= @test_cases.select {|c| c.test_status == :pending}.length end |
#run ⇒ Object
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 76 |
# File 'lib/beaker/test_suite.rb', line 38 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 #all failure modes cause us to kick out early on failure when :error @logger.warn msg break if fail_mode #all failure modes cause use to kick out early on error 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
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/beaker/test_suite.rb', line 78 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
120 121 122 |
# File 'lib/beaker/test_suite.rb', line 120 def skipped_tests @skipped_tests ||= @test_cases.select { |c| c.test_status == :skip }.length end |
#success? ⇒ Boolean
95 96 97 98 |
# File 'lib/beaker/test_suite.rb', line 95 def success? fail_without_test_run sum_failed == 0 end |
#test_count ⇒ Object
104 105 106 |
# File 'lib/beaker/test_suite.rb', line 104 def test_count @test_count ||= @test_cases.length end |