class SleepingKingStudios::Tasks::Ci::RSpecRunner

Service object to run RSpec as an external process with the specified parameters.

Public Instance Methods

call(env: {}) click to toggle source
# File lib/sleeping_king_studios/tasks/ci/rspec_runner.rb, line 12
def call env: {}, files: [], options: [], report: true
  report  = 'tmp/ci/rspec.json' if report && !report.is_a?(String)
  command =
    build_command(
      :env     => env,
      :files   => files,
      :options => options,
      :report  => report
    ) # end build_command

  stream_process(command)

  report ? load_report(:report => report) : {}
end

Private Instance Methods

base_command() click to toggle source
# File lib/sleeping_king_studios/tasks/ci/rspec_runner.rb, line 29
def base_command
  'bundle exec rspec'
end
build_options(files:, options:, report:, **_kwargs) click to toggle source
# File lib/sleeping_king_studios/tasks/ci/rspec_runner.rb, line 33
def build_options files:, options:, report:, **_kwargs
  options += ['--format=json', "--out=#{report}"] if report

  super :files => files, :options => options
end
load_report(report: raw = File.read report) click to toggle source
# File lib/sleeping_king_studios/tasks/ci/rspec_runner.rb, line 39
def load_report report:
  raw = File.read report

  return {} if raw.empty?

  json = JSON.parse raw
  hsh  = json['summary']

  hsh['error_count'] = parse_errors(json['summary_line'])

  hsh
rescue
  {}
end
parse_errors(summary) click to toggle source
# File lib/sleeping_king_studios/tasks/ci/rspec_runner.rb, line 54
def parse_errors summary
  return 0 unless summary && !summary.empty?

  match = summary.match(/(?<digits>\d+) error/)

  match ? match[:digits].to_i : 0
end