Class: LearnTest::Reporter
- Inherits:
-
Object
- Object
- LearnTest::Reporter
- Defined in:
- lib/learn_test/reporter.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
Class Method Summary collapse
Instance Method Summary collapse
- #failed_reports ⇒ Object
-
#initialize(strategy, options = {}) ⇒ Reporter
constructor
A new instance of Reporter.
- #report(out: STDOUT) ⇒ Object
- #retry_failed_reports ⇒ Object
Constructor Details
#initialize(strategy, options = {}) ⇒ Reporter
Returns a new instance of Reporter.
17 18 19 20 21 22 |
# File 'lib/learn_test/reporter.rb', line 17 def initialize(strategy, = {}) @strategy = strategy @output_path = [:output_path] || File.join(Dir.home, '.learn.debug') @client = [:client] || LearnTest::Client.new @debug = [:debug] end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
9 10 11 |
# File 'lib/learn_test/reporter.rb', line 9 def debug @debug end |
#output_path ⇒ Object
Returns the value of attribute output_path.
9 10 11 |
# File 'lib/learn_test/reporter.rb', line 9 def output_path @output_path end |
Class Method Details
.report(strategy, options = {}) ⇒ Object
11 12 13 14 15 |
# File 'lib/learn_test/reporter.rb', line 11 def self.report(strategy, = {}) reporter = new(strategy, ) reporter.report reporter.retry_failed_reports end |
Instance Method Details
#failed_reports ⇒ Object
24 25 26 27 |
# File 'lib/learn_test/reporter.rb', line 24 def failed_reports return {} unless File.exists?(output_path) JSON.load(File.read(output_path)) || {} end |
#report(out: STDOUT) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/learn_test/reporter.rb', line 46 def report(out: STDOUT) results = strategy.results endpoint = strategy.service_endpoint augment_results!(results) unless client.post_results(endpoint, results) if @debug out.puts 'There was a problem connecting to Learn. Not pushing test results.'.red end save_failed_attempt(endpoint, results) end end |
#retry_failed_reports ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/learn_test/reporter.rb', line 29 def retry_failed_reports previous_reports = failed_reports previous_reports.delete_if do |endpoint, results| results.delete_if do |result| !!client.post_results(endpoint, result) end.empty? end if previous_reports.empty? FileUtils.rm_f(output_path) else File.open(output_path, "w") do |file| file.write("#{JSON.dump(previous_reports)}\n") end end end |