Class: RspecDispatch::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_dispatch/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rspec_data) ⇒ Report

Returns a new instance of Report.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rspec_dispatch/report.rb', line 8

def initialize(rspec_data)
	success_calculation = ((1 - (rspec_data[:failure_count].to_f/rspec_data[:example_count].to_f)) * 100).to_s[0..5]

	if RspecDispatch.configuration.verbose == true

		if rspec_data[:duration].to_f > 60
			custom_duration = "#{(rspec_data[:duration].to_f / 60).to_s[0..5]} minutes."
		else
			custom_duration = "#{rspec_data[:duration]} seconds."
		end

		puts "\nRSpec Dispatch ----\n"
		puts "Duration: #{custom_duration}\n"
		puts "Example Count: #{rspec_data[:example_count]}\n"
		puts "Success Rate: #{success_calculation}%"
	end

	self.rspec_data = rspec_data
end

Instance Attribute Details

#monitor_dataObject

Returns the value of attribute monitor_data.



6
7
8
# File 'lib/rspec_dispatch/report.rb', line 6

def monitor_data
  @monitor_data
end

#rspec_dataObject

Returns the value of attribute rspec_data.



6
7
8
# File 'lib/rspec_dispatch/report.rb', line 6

def rspec_data
  @rspec_data
end

Instance Method Details

#deliverObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rspec_dispatch/report.rb', line 28

def deliver
	endpoint = RspecDispatch.configuration.service_url

	payload = {
		custom_data: RspecDispatch.configuration.custom_data,
		rspec_data: self.rspec_data,
		failures: self.monitor_data.failures,
		successes: self.monitor_data.successes,
		pending: self.monitor_data.pending
	}

	begin
		response = HTTParty.post(endpoint,
														 body: payload.to_json,
														 headers: {'Content-Type' => 'application/json'})

		body = response.body
		if (200..206).include?(response.code.to_i)
			if RspecDispatch.configuration.verbose == true
				puts "\nResponse Status: #{response.code}\n"
				if body.blank? || body == ''
					body = "*no content*"
				end
				puts "Response Body: #{body}"
			end

		else
			puts "\nResponse: ERROR (status #{response.code})\n"
		end

	rescue Errno::ECONNREFUSED
		puts "RSpec Dispatch: ERROR - Could not connect to given endpoint. Ensure that you have properly configured your target service url in the configuration block.  See Documentation at: https://github.com/theef/rspec_dispatch"
	end

end