class SbFormat

Attributes

summary[RW]

Public Class Methods

new(output) click to toggle source
# File lib/sbformat.rb, line 8
def initialize output
  @output = output
  @testsb = []
  @passed = []
  @failed = []
  @pending = []
  @jsonOutput = {}
  @projectName = 'SB'
  @footerMessage = ''
  @outPath = ''
  @documentation = false
  @count = 0

  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 false
  end
end

Public Instance Methods

close(notification) click to toggle source
# File lib/sbformat.rb, line 228
def close notification # NullNotification
  # ARGV.each do|a|
  #   puts "Argument: #{a}"
  # end
end
dump_failures(notification) click to toggle source
# File lib/sbformat.rb, line 207
def dump_failures notification # ExamplesNotification
  # @output << "\nFAILING\n\t"
  # # For every failed example...
  # @output << notification.failed_examples.map do |example|
  #   # Extract the full description of the example

  #   full_description = example.full_description
  #   # Extract the example location in the file
  #   location = example.location
  #   #- #{example.execution_result.exception.message}

  #   "#{example.description} - #{full_description} - #{example.execution_result.status} - #{location} - #{example.example_group} - #{example.exception.class}"
  # end.join("\n\n\t")
end
dump_pending(notification) click to toggle source
# File lib/sbformat.rb, line 222
def dump_pending notification # ExamplesNotification
  # @output << "\n\nPENDING:\n\t"

  # @output << notification.pending_examples.map {|example| example.full_description + " - " + example.location + " - #{example.execution_result.pending_message}"}.join("\n\t")
end
dump_summary(notification) click to toggle source
# File lib/sbformat.rb, line 107
def dump_summary notification # SummaryNotification
  groupArray = @testsb.map{ |a|
    {
      group: a[:group].to_s.split('::')[2],
      status: a[:status],
      location: a[:location],
      runtime: a[:runtime],
      id: a[:id]
    }
  }


  groupNames = groupArray.map{|a| a[:group]}.uniq
  suits = groupNames.map do |g|
    status = 'P'
    passCount = 0;
    failCount = 0;
    pendCount = 0;
    count = 0
    totalTime = 0
    location = ''
    id = 0

    groupArray.each do |c|
      if c[:group] == g
        count = count + 1
        location = c[:location]
        totalTime = totalTime + c[:runtime]
        id = c[:id]

        if c[:status] == 'pending'
          pendCount = pendCount + 1

          if status == 'P'
            status = 'W'
          elsif status == 'F'
            status = 'FW'
          end
        elsif c[:status] == 'failed'
          failCount = failCount + 1

          if status == 'P'
            status = 'F'
          elsif status == 'W'
            status = 'FW'
          end
        else
          passCount = passCount + 1
        end
      end
    end

    groupTests = @testsb.select{|y| y[:group].to_s.split('::')[2] == g}

    {
        group: g,
        status: status,
        location: location,
        testCount: count,
        passedCount: passCount,
        failedCount: failCount,
        pendingCount: pendCount,
        totalTimeForSuit: RSpec::Core::Formatters::Helpers.format_duration(totalTime.round(3)),
        grpTests: groupTests,
        id: id
    }
  end

  summary = {
    duration: RSpec::Core::Formatters::Helpers.format_duration(notification.duration.round(3)),
    groupCount: suits.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
  }
  # @output << "\n\nFinished in #{RSpec::Core::Formatters::Helpers.format_duration(notification.duration)}.\n"
  jo = @jsonOutput
  jo[:summary] = summary
  jo[:allTests] = @testsb
  jo[:pending] = @pending
  jo[:failed] = @failed
  jo[:passed] = @passed
  jo[:suits] = suits
  jo[:groupNames] = groupNames

  externalDetails = {}
  externalDetails[:userDetails] = {
    projectName: @projectName,
    footerMessage: @footerMessage,
    outPath: @outPath,
    documentation: @documentation
  }
  generator = HtmlGenerator.new(jo.to_json, externalDetails.to_json)
  generator.createHtml

  # @output << "Wrote the file in formattor/report.json"
end
example_failed(notification) click to toggle source
# File lib/sbformat.rb, line 66
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
  }
  @count = @count + 1
  @testsb.push(test)
  @failed.push(test)
  print "F"
end
example_passed(notification) click to toggle source
# File lib/sbformat.rb, line 47
def example_passed 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
  }
  @count = @count + 1
  @testsb.push(test)
  @passed.push(test)
  print "."

end
example_pending(notification) click to toggle source
# File lib/sbformat.rb, line 89
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
  }
  @count = @count + 1
  @testsb.push(test)
  @pending.push(test)
  print "*"
end