Class: Scarpe::Components::MinitestResult
- Inherits:
-
Object
- Object
- Scarpe::Components::MinitestResult
- Defined in:
- lib/scarpe/components/minitest_result.rb
Overview
A MinitestResult imports a JSON file from a minitest_export_reporter. But instead of creating a Minitest::Test to report the result, the MinitestResult is just a queryable Ruby object.
MinitestResult assumes there will be only one class and one method in the JSON, which is true for Scarpe but not necessarily in general.
Instance Attribute Summary collapse
-
#assertions ⇒ Object
readonly
Returns the value of attribute assertions.
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
Instance Method Summary collapse
- #check(expect_result: :success, min_asserts: nil, max_asserts: nil) ⇒ Object
- #console_summary ⇒ Object
- #error? ⇒ Boolean
- #error_message ⇒ Object
- #fail? ⇒ Boolean
- #fail_message ⇒ Object
-
#initialize(filename) ⇒ MinitestResult
constructor
A new instance of MinitestResult.
- #one_word_result ⇒ Object
- #passed? ⇒ Boolean
- #result_and_message ⇒ Object
- #skip? ⇒ Boolean
- #skip_message ⇒ Object
Constructor Details
#initialize(filename) ⇒ MinitestResult
Returns a new instance of MinitestResult.
20 21 22 23 24 25 26 27 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 |
# File 'lib/scarpe/components/minitest_result.rb', line 20 def initialize(filename) data = JSON.parse File.read(filename) unless data.size == 1 # We would want a different interface to support this in general. For now we don't # need it to work in general. raise "Scarpe::Components::MinitestResult only supports one class and method in results!" end item = data.first @assertions = item["assertions"] @method_name = item["name"] @class_name = item["klass"] @time = item["time"] @metadata = item.key?("metadata") ? item["metadata"]: {} @skip = false @exceptions = [] @failures = [] item["failures"].each do |f| # JSON.parse ignores json_class and won't create an arbitrary object. That's good # because Minitest::UnexpectedError seems to load in a bad way, so we don't want # it to auto-instantiate. d = JSON.parse f[1] msg = d["m"] case d["json_class"] when "Minitest::UnexpectedError" @exceptions << msg when "Minitest::Skip" @skip = msg when "Minitest::Assertion" @failures << msg else raise Scarpe::InternalError, "Didn't expect type #{t.inspect} as exception type when importing Minitest tests!" end end end |
Instance Attribute Details
#assertions ⇒ Object (readonly)
Returns the value of attribute assertions.
16 17 18 |
# File 'lib/scarpe/components/minitest_result.rb', line 16 def assertions @assertions end |
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
18 19 20 |
# File 'lib/scarpe/components/minitest_result.rb', line 18 def class_name @class_name end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
17 18 19 |
# File 'lib/scarpe/components/minitest_result.rb', line 17 def method_name @method_name end |
Instance Method Details
#check(expect_result: :success, min_asserts: nil, max_asserts: nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/scarpe/components/minitest_result.rb', line 80 def check(expect_result: :success, min_asserts: nil, max_asserts: nil) unless [:error, :fail, :skip, :success].include?(expect_result) raise Scarpe::InternalError, "Expected test result should be one of [:success, :fail, :error, :skip]!" end res, msg = if expect_result.to_s != res return [false, "Expected #{expect_result} but got #{res}: #{msg}!"] end if min_asserts && @assertions < min_asserts return [false, "Expected success with at least #{min_asserts} assertions but found only #{@assertions}!"] end if max_asserts && @assertions > max_asserts return [false, "Expected success with no more than #{max_asserts} assertions but found only #{@assertions}!"] end [true, ""] end |
#console_summary ⇒ Object
73 74 75 76 77 78 |
# File 'lib/scarpe/components/minitest_result.rb', line 73 def console_summary return "Error(s): #{@exceptions.inspect}" if self.error? return "Failure: #{@failures.inspect}" if self.fail? return "Skip: #{.inspect}" if self.skip? "Success!" end |
#error? ⇒ Boolean
100 101 102 |
# File 'lib/scarpe/components/minitest_result.rb', line 100 def error? !@exceptions.empty? end |
#error_message ⇒ Object
116 117 118 |
# File 'lib/scarpe/components/minitest_result.rb', line 116 def @exceptions[0] end |
#fail? ⇒ Boolean
104 105 106 |
# File 'lib/scarpe/components/minitest_result.rb', line 104 def fail? !@failures.empty? end |
#fail_message ⇒ Object
120 121 122 |
# File 'lib/scarpe/components/minitest_result.rb', line 120 def @failures[0] end |
#one_word_result ⇒ Object
59 60 61 62 63 64 |
# File 'lib/scarpe/components/minitest_result.rb', line 59 def one_word_result return "error" if self.error? return "fail" if self.fail? return "skip" if self.skip? "success" end |
#passed? ⇒ Boolean
112 113 114 |
# File 'lib/scarpe/components/minitest_result.rb', line 112 def passed? @exceptions.empty? && @failures.empty? && !@skip end |
#result_and_message ⇒ Object
66 67 68 69 70 71 |
# File 'lib/scarpe/components/minitest_result.rb', line 66 def return ["error", ] if self.error? return ["fail", ] if self.fail? return ["skip", ] if self.skip? ["success", "OK"] end |
#skip? ⇒ Boolean
108 109 110 |
# File 'lib/scarpe/components/minitest_result.rb', line 108 def skip? @skip ? true : false end |
#skip_message ⇒ Object
124 125 126 |
# File 'lib/scarpe/components/minitest_result.rb', line 124 def @skip end |