Skip to content

Commit e18b178

Browse files
author
Ben Lerner
committed
fix display when tests are completely broken
1 parent 8fbdf08 commit e18b178

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

app/views/grades/_show_simple_list.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<div id="tests">
2+
<% if @tests.nil %>
3+
<pre><%= @grading_output.output %></pre>
4+
<% else %>
25
<% @tests.each_with_index do |t, i| %>
36
<% if t[:passed]
47
style = "alert-success"
@@ -38,4 +41,5 @@
3841
<% end %>
3942
</div>
4043
<% end %>
44+
<% end %>
4145
</div>

lib/json_parser.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
class JsonParser
2-
attr_reader :json, :test_count, :tests, :commentary, :passed_count, :time_taken
2+
attr_reader :json, :test_count, :tests, :commentary, :passed_count, :time_taken, :output
33
attr_reader :filename
44
attr_reader :score, :max_score
55

66
def initialize(json, filename=nil)
77
@filename = filename
88
@json = json
9-
@test_count = json['tests'].count
10-
@tests = json['tests'].map.with_index do |t, num|
9+
@test_count = json['tests']&.count
10+
@output = json['output']
11+
@tests = json['tests']&.map.with_index do |t, num|
1112
t = t.clone
1213
weight = t.delete('weight') || t.delete('max_score') || t.delete('max-score')
1314
score = t.delete('score')
@@ -30,8 +31,8 @@ def initialize(json, filename=nil)
3031
}
3132
end
3233
end
33-
@passed_count = @tests.count { |t| t[:passed] }
34-
@score = @json['score']
35-
@max_score = @json['max-score']
34+
@passed_count = @tests&.count { |t| t[:passed] } || 0
35+
@score = @json['score'] || 0
36+
@max_score = @json['max-score'] || 0
3637
end
3738
end

0 commit comments

Comments
 (0)