Skip to content

Commit

Permalink
Parse the test message for all test frameworks implemented in super c…
Browse files Browse the repository at this point in the history
…lass
  • Loading branch information
tomas-stefano committed Feb 19, 2014
1 parent c0e5549 commit c2b7dd8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
24 changes: 24 additions & 0 deletions lib/infinity_test/test_framework/base.rb
Expand Up @@ -19,7 +19,21 @@ def binary
raise NotImplementedError, "not implemented in #{self}"
end

# Parse the test results based by the framework patterns.
# <b>The subclass must implement the #patterns method.</b>
#
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

Expand All @@ -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
29 changes: 4 additions & 25 deletions lib/infinity_test/test_framework/rspec.rb
Expand Up @@ -14,38 +14,17 @@ 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

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

0 comments on commit c2b7dd8

Please sign in to comment.