class RsFormat
Attributes
summary[RW]
Public Class Methods
new(y)
click to toggle source
# File lib/rsformat.rb, line 8 def initialize y @summary = {} @failed = [] @groups = [] @count = 0 @groupCount = 0 @projectName = 'SB' @footerMessage = '' @outPath = '' @documentation = false if File.exist?('.sbfrc') begin x = JSON.parse(IO.read('.sbfrc')) if(x.has_key? 'project') @projectName = x['project'] end if(x.has_key? 'footer') @footerMessage = x['footer'] end if(x.has_key? 'outPath') @outPath = x['outPath'] end if(x.has_key? 'document') @documentation = x['document'].eql?('true') ? true : false end rescue puts 'rescue block' end else puts "No user specification (.sbfrc) found. Using default configuration." end end
Public Instance Methods
addOrAppendGroup(test, notification)
click to toggle source
# File lib/rsformat.rb, line 164 def addOrAppendGroup test, notification grps = @groups.select{|y| y[:grpName] == notification.example.example_group.to_s.split('::')[2]} if(!grps.any?) # No entry for this group Yet. grp = { grpId: @groupCount + 1, grpName: notification.example.example_group.to_s.split('::')[2], status: notification.example.execution_result.status.to_s == "passed" ? "P" : (notification.example.execution_result.status.to_s == "failed" ? "F" : (notification.example.execution_result.status.to_s == "pending" ? "W" : "X")), location: notification.example.location.split(":")[0], totalTimeForSuit: notification.example.execution_result.run_time.round(3), testCount: 1, passedCount: notification.example.execution_result.status.to_s == "passed" ? 1 : 0, failedCount: notification.example.execution_result.status.to_s == "failed" ? 1 : 0, pendingCount: notification.example.execution_result.status.to_s == "pending" ? 1 : 0, grpTests: [test], } @groups.push(grp) @groupCount = @groupCount + 1 else # grp status can change if(grps[0][:status] == "P") grps[0][:status] = notification.example.execution_result.status.to_s == "failed" ? "F" : (notification.example.execution_result.status.to_s == "pending" ? "W" : "P") elsif (grps[0][:status] == "F") grps[0][:status] = notification.example.execution_result.status.to_s == "pending" ? "FW" : "F" elsif (grps[0][:status] == "W") grps[0][:status] = notification.example.execution_result.status.to_s == "failed" ? "FW" : "W" end # grp total time for suit grps[0][:totalTimeForSuit] = (grps[0][:totalTimeForSuit] + notification.example.execution_result.run_time).round(3) # grp test count grps[0][:testCount] = grps[0][:testCount] + 1 # grp passed / failed / pending count if(notification.example.execution_result.status.to_s == "passed") grps[0][:passedCount] = grps[0][:passedCount] + 1 elsif(notification.example.execution_result.status.to_s == "failed") grps[0][:failedCount] = grps[0][:failedCount] + 1 elsif(notification.example.execution_result.status.to_s == "pending") grps[0][:pendingCount] = grps[0][:pendingCount] + 1 end # grp Tests should be added. grps[0][:grpTests].push(test) end end
close(notification)
click to toggle source
# File lib/rsformat.rb, line 132 def close notification # NullNotification puts "\n" puts "---------------------------------------------------------" puts "Total Suits : #{@summary[:groupCount]}" puts "Total Tests : #{@summary[:testCount]}" puts "Total Passed : #{@summary[:passCount]}" puts "Total Failed : #{@summary[:failureCount]}" puts "Total Pending : #{@summary[:pendingCount]}" puts "Total Time Taken : #{@summary[:duration]}" puts "---------------------------------------------------------" if(@documentation) if(@failed.length == 0) puts "******************* NO Exceptions found **************************" else puts "=====================Exceptions==========================" cnt = 0 @failed.each do |failedTest| exMessage = failedTest[:exception][:message].gsub("\n","") exType = failedTest[:exception][:type] puts "\n#{cnt + 1}. #{failedTest[:fullName]}" puts "Exception : #{exType}" puts "Message : #{exMessage}" cnt = cnt + 1 puts "\n" end puts "=========================================================" end end end
dump_summary(notification)
click to toggle source
# File lib/rsformat.rb, line 106 def dump_summary notification # SummaryNotification # puts "\nTesting ends ... Generating Report" # puts "Total Tests: #{@count}" # puts @groups.length @summary = { duration: RSpec::Core::Formatters::Helpers.format_duration(notification.duration.round(3)), groupCount: @groups.length, testCount: notification.example_count, pendingCount: notification.pending_count, failureCount: notification.failure_count, passCount: notification.example_count - ( notification.pending_count + notification.failure_count), projectName: @projectName } userData = { projectName: @projectName, footerMessage: @footerMessage, outPath: @outPath, documentation: @documentation } html = Htmler.new(JSON.generate(@summary), JSON.generate(@groups), JSON.generate(userData)) html.inits end
example_failed(notification)
click to toggle source
# File lib/rsformat.rb, line 64 def example_failed notification # FailedExampleNotification test = { group: notification.example.example_group, name: notification.example.description, fullName: notification.example.full_description, status: notification.example.execution_result.status.to_s, location: notification.example.location.split(":")[0], lineNo: notification.example.location.split(":")[1], runtime: notification.example.execution_result.run_time, id: @count + 1, exception: { type: notification.example.exception.class, message: notification.example.execution_result.exception.message, backtrace: notification.example.exception.backtrace }, pendingMessage: notification.example.execution_result.pending_message } addOrAppendGroup test, notification @count = @count + 1 @failed.push(test) print "F" end
example_passed(notification)
click to toggle source
# File lib/rsformat.rb, line 47 def example_passed notification # ExampleNotification test = { name: notification.example.description, fullName: notification.example.full_description, status: notification.example.execution_result.status.to_s, location: notification.example.location.split(":")[0], lineNo: notification.example.location.split(":")[1], runtime: notification.example.execution_result.run_time, pendingMessage: notification.example.execution_result.pending_message, id: @count + 1 } addOrAppendGroup test, notification @count = @count + 1 print "." end
example_pending(notification)
click to toggle source
# File lib/rsformat.rb, line 88 def example_pending notification # ExampleNotification test = { group: notification.example.example_group, name: notification.example.description, fullName: notification.example.full_description, status: notification.example.execution_result.status.to_s, location: notification.example.location.split(":")[0], lineNo: notification.example.location.split(":")[1], runtime: notification.example.execution_result.run_time, pendingMessage: notification.example.execution_result.pending_message, id: @count + 1 } addOrAppendGroup test, notification @count = @count + 1 print "*" end