Class: Probatio::ProbaOutputter

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

Instance Method Summary collapse

Instance Method Details

#on_over(ev) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/probatio/plugins.rb', line 191

def on_over(ev)

# TODO unplug if --mute or some switch like that...
  r = Probatio.recorder_plugin

  flh = r.failed_tests.collect(&:to_h).each { |h| h.delete(:n) }
  fls = Cerata.table_to_s(flh, '  ')

  rb = {}
    #
  rv =
    File.exist?('.ruby-version') &&
    File.readlines('.ruby-version').find { |l| ! l.strip.start_with?('#') }
    #
  rb[:v] = ".ruby-version:#{rv.strip}" if rv
  rb[:p] = File.join(
    RbConfig::CONFIG['bindir'],
    RbConfig::CONFIG['ruby_install_name'])
  rb[:d] = RUBY_DESCRIPTION
  rb[:l] = RUBY_PATCHLEVEL
    #
  #rb = Cerata.horizontal_h_to_s(rb)
  rb = Cerata.vertical_h_to_s(rb, '  ')

  env = Cerata.vertical_h_to_s(
    ENV.filter { |k, _|
      k.match?(/^(RUBY_|GEM_|(HOME|PATH|USER|SHELL|PWD)$)/) },
    '  ')

  File.open(Probatio.opath, 'wb') do |o|
    o << '# ' << Probatio.opath << "\n"
    o << "{\n"
    o << "argv: " << Cerata.horizontal_a_to_s(ARGV) << ",\n"
    o << "failures:\n"
    #o << "  [\n"
    #fls.each { |fl| o << '  ' << fl << ",\n" }
    #o << "  ],\n"
    o << fls << ",\n"
    o << "duration: #{Probatio.to_time_s(r.total_duration).inspect},\n"
    o << "probatio: { v: #{Probatio::VERSION.inspect} },\n"
    o << "ruby:\n#{rb},\n"
    o << "some_env:\n#{env},\n"
    o << "}\n"
  end
end