class ReportFactory::Rspec::API

An RSpec formatter that formats json from the test run

Public Class Methods

base_url() click to toggle source
# File lib/report_factory/rspec/api.rb, line 41
def self.base_url
  ReportFactory::Rspec.url
end
create_report_url() click to toggle source
# File lib/report_factory/rspec/api.rb, line 53
def self.create_report_url
  URI.parse("#{base_url}/api/v1/projects/#{project_name}/reports/rspec")
end
format_headers() click to toggle source
# File lib/report_factory/rspec/api.rb, line 20
def self.format_headers
  {
    'Content-Type': 'application/json',
    'X-API-KEY' => x_api_key
  }
end
format_payload(report_hash) click to toggle source
# File lib/report_factory/rspec/api.rb, line 27
def self.format_payload(report_hash)
  attributes = { tags: tags }.merge(report_hash)
  {
    data: {
      type: 'rspec_report',
      attributes: attributes
    }
  }
end
project_name() click to toggle source
# File lib/report_factory/rspec/api.rb, line 45
def self.project_name
  ReportFactory::Rspec.project_name
end
send_report(report_hash) click to toggle source
# File lib/report_factory/rspec/api.rb, line 11
def self.send_report(report_hash)
  uri = create_report_url
  request = Net::HTTP::Post.new(uri.request_uri, format_headers)
  request.body = format_payload(report_hash).to_json
  net_http = Net::HTTP.new(uri.host, uri.port)
  net_http.use_ssl = true if uri.scheme == 'https'
  net_http.request(request)
end
tags() click to toggle source
# File lib/report_factory/rspec/api.rb, line 49
def self.tags
  ReportFactory::Rspec.tags
end
x_api_key() click to toggle source
# File lib/report_factory/rspec/api.rb, line 37
def self.x_api_key
  ReportFactory::Rspec.auth_token
end