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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#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, config, 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, config, fail_mode = nil) ⇒ TestSuite
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 |
# File 'lib/beaker/test_suite.rb', line 21 def initialize(name, hosts, , config, fail_mode = nil) @name = name.gsub(/\s+/, '-') @hosts = hosts @run = false = @config = config @fail_mode = [:fail_mode] || fail_mode @logger = [:logger] @test_cases = [] @test_files = [] [:tests].each do |root| if File.file? root then @test_files << root else @test_files += Dir.glob( File.join(root, "**/*.rb") ).select { |f| File.file?(f) } end end 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
#config ⇒ Object (readonly)
Returns the value of attribute config.
19 20 21 |
# File 'lib/beaker/test_suite.rb', line 19 def config @config end |
#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 end |
Instance Method Details
#errored_tests ⇒ Object
123 124 125 |
# File 'lib/beaker/test_suite.rb', line 123 def errored_tests @errored_tests ||= @test_cases.select { |c| c.test_status == :error }.length end |
#fail_without_test_run ⇒ Object
102 103 104 |
# File 'lib/beaker/test_suite.rb', line 102 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
111 112 113 |
# File 'lib/beaker/test_suite.rb', line 111 def failed? !success? end |
#failed_tests ⇒ Object
127 128 129 |
# File 'lib/beaker/test_suite.rb', line 127 def failed_tests @failed_tests ||= @test_cases.select { |c| c.test_status == :fail }.length end |
#passed_tests ⇒ Object
119 120 121 |
# File 'lib/beaker/test_suite.rb', line 119 def passed_tests @passed_tests ||= @test_cases.select { |c| c.test_status == :pass }.length end |
#pending_tests ⇒ Object
135 136 137 |
# File 'lib/beaker/test_suite.rb', line 135 def pending_tests @pending_tests ||= @test_cases.select {|c| c.test_status == :pending}.length end |
#run ⇒ Object
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 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/beaker/test_suite.rb', line 49 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, config, , 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
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/beaker/test_suite.rb', line 89 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
131 132 133 |
# File 'lib/beaker/test_suite.rb', line 131 def skipped_tests @skipped_tests ||= @test_cases.select { |c| c.test_status == :skip }.length end |
#success? ⇒ Boolean
106 107 108 109 |
# File 'lib/beaker/test_suite.rb', line 106 def success? fail_without_test_run sum_failed == 0 end |
#test_count ⇒ Object
115 116 117 |
# File 'lib/beaker/test_suite.rb', line 115 def test_count @test_count ||= @test_cases.length end |