class Lopata::Client

@private

Attributes

build_number[R]
project_code[R]
url[R]

Public Class Methods

new() click to toggle source
# File lib/lopata/observers/web_logger.rb, line 37
def initialize
  params = Lopata.configuration.web_logging_params
  raise "Web logging is not initailzed" unless params
  @url = HTTParty.normalize_base_uri(params[:url])
  @project_code = params[:project_code]
  @build_number = params[:build_number]
end

Public Instance Methods

add_attempt(scenario, finished) click to toggle source
# File lib/lopata/observers/web_logger.rb, line 49
def add_attempt(scenario, finished)
  status = scenario.failed? ? Lopata::FAILED : Lopata::PASSED
  steps = scenario.steps.map { |s| step_hash(s) }
  request = { status: status, steps: steps, launch: { id: @launch_id, finished: finished } }
  test = test_id(scenario)
  post("/tests/#{test}/attempts.json", body: request)
end
start(count) click to toggle source
# File lib/lopata/observers/web_logger.rb, line 45
def start(count)
  @launch_id = JSON.parse(post("/projects/#{project_code}/builds/#{build_number}/launches.json", body: {total: count}).body)['id']
end
step_hash(step) click to toggle source
# File lib/lopata/observers/web_logger.rb, line 57
def step_hash(step)
  hash = { status: step.status, title: step.title }
  if step.failed?
    hash[:message] = error_message_for(step)
    hash[:backtrace] = backtrace_for(step)
  end
  hash
end
test_id(scenario) click to toggle source
# File lib/lopata/observers/web_logger.rb, line 66
def test_id(scenario)
  request = {
    test: {
      project_code: project_code,
      title: scenario.title,
      scenario: scenario.title,
      build_number: build_number
    }
  }
  response = post("/tests.json", body: request)
  JSON.parse(response.body)["id"]
end
to_full_rescan() click to toggle source
# File lib/lopata/observers/web_logger.rb, line 83
def to_full_rescan
  to_rerun + get_json("/projects/#{project_code}/builds/#{build_number}/failures.json")
end
to_rerun() click to toggle source
# File lib/lopata/observers/web_logger.rb, line 79
def to_rerun
  get_json("/projects/#{project_code}/builds/#{build_number}/suspects.json")
end

Private Instance Methods

backtrace_for(step) click to toggle source
# File lib/lopata/observers/web_logger.rb, line 118
def backtrace_for(step)
  msg = ''
  if step.exception
    msg = backtrace_formatter.format(step.exception.backtrace).join("\n")
    msg << "\n"
  end
  msg
end
backtrace_formatter() click to toggle source
# File lib/lopata/observers/web_logger.rb, line 127
def backtrace_formatter
  @backtrace_formatter ||= Lopata::Observers::BacktraceFormatter.new
end
error_message_for(step) click to toggle source
# File lib/lopata/observers/web_logger.rb, line 110
def error_message_for(step)
  if step.exception
    backtrace_formatter.error_message(step.exception)
  else
    'Empty error message'
  end
end
get_json(path) click to toggle source
# File lib/lopata/observers/web_logger.rb, line 89
def get_json(path)
  JSON.parse(self.class.get(path, base_uri: url).body)
end
patch(*args) click to toggle source
# File lib/lopata/observers/web_logger.rb, line 97
def patch(*args)
  self.class.patch(*with_base_uri(args))
end
post(*args) click to toggle source
# File lib/lopata/observers/web_logger.rb, line 93
def post(*args)
  self.class.post(*with_base_uri(args))
end
with_base_uri(args = []) click to toggle source
# File lib/lopata/observers/web_logger.rb, line 101
def with_base_uri(args = [])
  if args.last.is_a? Hash
    args.last[:base_uri] = url
  else
    args << { base_uri: url }
  end
  args
end