Class: Blade::TestResults
- Inherits:
-
Object
- Object
- Blade::TestResults
- Defined in:
- lib/blade/test_results.rb
Constant Summary collapse
- STATUS_DOTS =
{ pass: ".", fail: "✗" }.with_indifferent_access
Instance Attribute Summary collapse
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(session_id) ⇒ TestResults
constructor
A new instance of TestResults.
- #process_begin(details) ⇒ Object
- #process_end(details) ⇒ Object
- #process_result(details) ⇒ Object
- #publish(message = {}) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(session_id) ⇒ TestResults
Returns a new instance of TestResults.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/blade/test_results.rb', line 6 def initialize(session_id) @session_id = session_id reset Blade.subscribe("/tests") do |details| if details[:session_id] == session_id event = details.delete(:event) try("process_#{event}", details) end end end |
Instance Attribute Details
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
4 5 6 |
# File 'lib/blade/test_results.rb', line 4 def failures @failures end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
4 5 6 |
# File 'lib/blade/test_results.rb', line 4 def results @results end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
4 5 6 |
# File 'lib/blade/test_results.rb', line 4 def session_id @session_id end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
4 5 6 |
# File 'lib/blade/test_results.rb', line 4 def state @state end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
4 5 6 |
# File 'lib/blade/test_results.rb', line 4 def total @total end |
Instance Method Details
#process_begin(details) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/blade/test_results.rb', line 25 def process_begin(details) reset @state = "running" @total = details[:total] publish(total: @total) end |
#process_end(details) ⇒ Object
44 45 46 47 |
# File 'lib/blade/test_results.rb', line 44 def process_end(details) @state = failures.zero? ? "finished" : "failed" publish(completed: true) end |
#process_result(details) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/blade/test_results.rb', line 32 def process_result(details) result = details.slice(:status, :name, :message) @results << result if result[:status] == "fail" @state = "failing" @failures += 1 end publish(result) end |
#publish(message = {}) ⇒ Object
49 50 51 |
# File 'lib/blade/test_results.rb', line 49 def publish( = {}) Blade.publish("/results", .merge(state: state, session_id: session_id)) end |
#reset ⇒ Object
18 19 20 21 22 23 |
# File 'lib/blade/test_results.rb', line 18 def reset @results = [] @state = "pending" @total = 0 @failures = 0 end |