Class: SbFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/sbformat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ SbFormat

Returns a new instance of SbFormat.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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

Instance Attribute Details

#summaryObject

Returns the value of attribute summary.



5
6
7
# File 'lib/sbformat.rb', line 5

def summary
  @summary
end

Instance Method Details

#close(notification) ⇒ Object

NullNotification



228
229
230
231
232
# File 'lib/sbformat.rb', line 228

def close notification # NullNotification
  # ARGV.each do|a|
  #   puts "Argument: #{a}"
  # end
end

#dump_failures(notification) ⇒ Object

ExamplesNotification



207
208
209
210
211
212
213
214
215
216
217
218
219
220
# 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) ⇒ Object

ExamplesNotification



222
223
224
225
226
# 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) ⇒ Object

SummaryNotification



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# 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) ⇒ Object

FailedExampleNotification



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 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) ⇒ Object

ExampleNotification



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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) ⇒ Object

ExampleNotification



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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