From c2b7dd89b936beee7f7c4314404a4f363e66f28b Mon Sep 17 00:00:00 2001 From: Tomas D'Stefano Date: Tue, 18 Feb 2014 22:31:10 -0300 Subject: [PATCH] Parse the test message for all test frameworks implemented in super class --- lib/infinity_test/test_framework/base.rb | 24 +++++++++++++++++++ lib/infinity_test/test_framework/rspec.rb | 29 ++++------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/lib/infinity_test/test_framework/base.rb b/lib/infinity_test/test_framework/base.rb index 402887c..a6959f1 100644 --- a/lib/infinity_test/test_framework/base.rb +++ b/lib/infinity_test/test_framework/base.rb @@ -19,7 +19,21 @@ def binary raise NotImplementedError, "not implemented in #{self}" end + # Parse the test results based by the framework patterns. + # The subclass must implement the #patterns method. + # def test_message=(message) + @test_message = final_results(message).join.gsub(/\e\[\d+?m/, '') # Clean ANSIColor strings + + patterns.each do |key, pattern| + spec_number = test_message[pattern, 1].to_i + instance_variable_set("@#{key}", spec_number) + end + + @test_message + end + + def patterns raise NotImplementedError, "not implemented in #{self}" end @@ -34,6 +48,16 @@ def failure? def pending? raise NotImplementedError, "not implemented in #{self}" end + + private + + def final_results(message) + lines = message.split("\n") + + patterns.map do |pattern_name, pattern| + lines.find { |line| line =~ pattern } + end.flatten.uniq + end end end end \ No newline at end of file diff --git a/lib/infinity_test/test_framework/rspec.rb b/lib/infinity_test/test_framework/rspec.rb index 284996f..e091054 100644 --- a/lib/infinity_test/test_framework/rspec.rb +++ b/lib/infinity_test/test_framework/rspec.rb @@ -14,6 +14,10 @@ def test_dir end alias :command_arguments :test_dir + def patterns + { :examples => /(\d+) example/, :failures => /(\d+) failure/, :pending => /(\d+) pending/ } + end + def success? @failures.zero? and @pending.zero? end @@ -21,31 +25,6 @@ def success? def failure? @failures > 0 end - - def test_message=(message) - @test_message = final_results(message).join.gsub(/\e\[\d+?m/, '') # Clean ANSIColor strings - - patterns.each do |key, pattern| - spec_number = test_message[pattern, 1].to_i - instance_variable_set("@#{key}", spec_number) - end - - @test_message - end - - private - - def final_results(message) - lines = message.split("\n") - - patterns.map do |pattern_name, pattern| - lines.find { |line| line =~ pattern } - end.flatten.uniq - end - - def patterns - { :examples => /(\d+) example/, :failures => /(\d+) failure/, :pending => /(\d+) pending/ } - end end end end \ No newline at end of file