Class: ReportFactory::Rspec::API

Inherits:
Object
  • Object
show all
Defined in:
lib/report_factory/rspec/api.rb

Overview

An RSpec formatter that formats json from the test run

Class Method Summary collapse

Class Method Details

.base_urlObject



41
42
43
# File 'lib/report_factory/rspec/api.rb', line 41

def self.base_url
  ReportFactory::Rspec.url
end

.create_report_urlObject



53
54
55
# 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_headersObject



20
21
22
23
24
25
# 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) ⇒ Object



27
28
29
30
31
32
33
34
35
# 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_nameObject



45
46
47
# File 'lib/report_factory/rspec/api.rb', line 45

def self.project_name
  ReportFactory::Rspec.project_name
end

.send_report(report_hash) ⇒ Object



11
12
13
14
15
16
17
18
# 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

.tagsObject



49
50
51
# File 'lib/report_factory/rspec/api.rb', line 49

def self.tags
  ReportFactory::Rspec.tags
end

.x_api_keyObject



37
38
39
# File 'lib/report_factory/rspec/api.rb', line 37

def self.x_api_key
  ReportFactory::Rspec.auth_token
end