Class: AnySpec::TestRunner
- Inherits:
-
Object
- Object
- AnySpec::TestRunner
- Defined in:
- lib/any-spec/test-runner.rb
Instance Attribute Summary collapse
-
#report ⇒ Object
Returns the value of attribute report.
-
#specification_extension ⇒ Object
Returns the value of attribute specification_extension.
-
#specification_root ⇒ Object
Returns the value of attribute specification_root.
-
#target_executable ⇒ Object
Returns the value of attribute target_executable.
-
#test_case_paths ⇒ Object
Returns the value of attribute test_case_paths.
-
#test_cases ⇒ Object
Returns the value of attribute test_cases.
Instance Method Summary collapse
-
#initialize(target_executable, test_specification_file) ⇒ TestRunner
constructor
A new instance of TestRunner.
- #message(string, color = :white) ⇒ Object
- #run_tests(silence = false) ⇒ Object
Constructor Details
#initialize(target_executable, test_specification_file) ⇒ TestRunner
Returns a new instance of TestRunner.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/any-spec/test-runner.rb', line 13 def initialize( target_executable, test_specification_file ) # Verify that the target executable exists and is in the current PATH @target_executable = target_executable.strip # Load the test specification file @test_specification_file = File.(test_specification_file) raise Exception, "The test specification file you supplied does not exist." unless(File.exist? @test_specification_file) test_spec = YAML::load_file(@test_specification_file) @specification_root = test_spec["specification_root"] @specification_extension = test_spec["specification_extension"] # Find and load test-case file paths @test_case_paths = Dir[File.join(File.split(@test_specification_file)[0], @specification_root, '**', "*" + @specification_extension)].sort # Instantiate the test cases @test_cases = @test_case_paths.map do |test_case| AnySpec::TestCase.new(test_case, @target_executable) end end |
Instance Attribute Details
#report ⇒ Object
Returns the value of attribute report.
6 7 8 |
# File 'lib/any-spec/test-runner.rb', line 6 def report @report end |
#specification_extension ⇒ Object
Returns the value of attribute specification_extension.
6 7 8 |
# File 'lib/any-spec/test-runner.rb', line 6 def specification_extension @specification_extension end |
#specification_root ⇒ Object
Returns the value of attribute specification_root.
6 7 8 |
# File 'lib/any-spec/test-runner.rb', line 6 def specification_root @specification_root end |
#target_executable ⇒ Object
Returns the value of attribute target_executable.
6 7 8 |
# File 'lib/any-spec/test-runner.rb', line 6 def target_executable @target_executable end |
#test_case_paths ⇒ Object
Returns the value of attribute test_case_paths.
6 7 8 |
# File 'lib/any-spec/test-runner.rb', line 6 def test_case_paths @test_case_paths end |
#test_cases ⇒ Object
Returns the value of attribute test_cases.
6 7 8 |
# File 'lib/any-spec/test-runner.rb', line 6 def test_cases @test_cases end |
Instance Method Details
#message(string, color = :white) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/any-spec/test-runner.rb', line 58 def (string, color = :white) if(@silence) @report << string else case color when :white then print( "\e[37m" ) when :red then print( "\e[31m" ) when :green then print( "\e[32m" ) when :grey then print( "\e[90m") end print string + "\e[0m" $stdout.flush end end |
#run_tests(silence = false) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/any-spec/test-runner.rb', line 30 def run_tests(silence = false) @report = "" @silence = silence "\nStarted\n" start_time = Time.now assertions = 0 failed_tests = [] @test_cases.each do |test_case| result = test_case.run ".", :green if(result) "F", :red if(!result) assertions += test_case.assertions failed_tests << test_case if(!result) end "\n\n" "Failures:\n\n" unless failed_tests.empty? failed_tests.each_index do |x| test_case = failed_tests[x] " #{x + 1}) " + test_case.path.gsub(File.split(@test_specification_file)[0], "") + "\n" test_case. + "\n\n" end "\n\nFinished in #{(Time.now - start_time).to_f} seconds.\n" pass_rate = format("%.2f",(100.0 - ((failed_tests.length.to_f) / @test_cases.length) * 100)) result_color = failed_tests.count == 0 ? :green : :red "#{@test_cases.length} tests, #{assertions} assertions, #{failed_tests.count} failures, #{pass_rate}% pass rate\n", result_color return @test_cases end |