Class: Course::Assessment::ProgrammingTestCaseReport::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/autoload/course/assessment/programming_test_case_report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_suite, test_case) ⇒ TestCase

Creates a new test case. This represents a <testcase> element.

Parameters:


58
59
60
61
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 58

def initialize(test_suite, test_case)
  @test_suite = test_suite
  @test_case = test_case
end

Instance Attribute Details

#test_suiteObject (readonly)

Returns the value of attribute test_suite


51
52
53
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 51

def test_suite
  @test_suite
end

Instance Method Details

#class_nameString

The name of the class.

Returns:

  • (String)

66
67
68
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 66

def class_name
  @test_case['classname']
end

#durationFloat|nil

The duration for running the test case.

Returns:

  • (Float|nil)

    The duration for the test case, nil if not recorded.


80
81
82
83
84
85
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 80

def duration
  @duration ||= begin
    duration = @test_case['time']
    duration ? duration.to_f : nil
  end
end

#error_contentsString|nil

If there's a error, return the contents of the error tag. This contains the full traceback.

Returns:

  • (String|nil)

    Full traceback of error, or nil if there's no error.


137
138
139
140
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 137

def error_contents
  return nil unless errored?
  @test_case.search('error')[0].children.to_s
end

#error_messageString|nil

If there's an error, return the error type and error message.

Returns:

  • (String|nil)

    A combined string with the error type and error message, nil if no error.


127
128
129
130
131
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 127

def error_message
  return nil unless errored?
  error_body = @test_case.search('error')[0]['message']
  "#{error_type}: #{error_body}"
end

#error_typeString|nil

If there's an error, return the error type attribute.

Returns:

  • (String|nil)

    The type attribute, nil if no error.


145
146
147
148
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 145

def error_type
  return nil unless errored?
  @test_case.search('error')[0]['type']
end

#errored?Boolean

Checks if the test case encountered an error.

Returns:

  • (Boolean)

180
181
182
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 180

def errored?
  !@test_case.search('./error').empty?
end

#expectedString

The expected value from running the test expression

Returns:

  • (String)

105
106
107
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 105

def expected
  @expected ||= ('expected')
end

#expressionString

The test expression

Returns:

  • (String)

98
99
100
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 98

def expression
  @expression ||= ('expression')
end

#failed?Boolean

Checks if the test case has failed.

Returns:

  • (Boolean)

194
195
196
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 194

def failed?
  !@test_case.search('./failure').empty?
end

#failure_contentsString|nil

If there's a failure, return the contents of the failure tag. This contains the full traceback.

Returns:

  • (String|nil)

    Full traceback of failure, nil if there's no failure.


164
165
166
167
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 164

def failure_contents
  return nil unless failed?
  @test_case.search('failure')[0].children.to_s
end

#failure_messageString|nil

If there's a failure, return the failure type and failure message.

nil if no failure.

Returns:

  • (String|nil)

    A combined string with the failure type and failure message,


154
155
156
157
158
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 154

def failure_message
  return nil unless failed?
  failure_body = @test_case.search('failure')[0]['message']
  "#{failure_type}: #{failure_body}"
end

#failure_typeString|nil

If there's a failure, return the failure type attribute.

Returns:

  • (String|nil)

    The type attribute, nil if there's no failure.


172
173
174
175
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 172

def failure_type
  return nil unless failed?
  @test_case.search('failure')[0]['type']
end

#hintString

A hint to help the student pass the test case

Returns:

  • (String)

112
113
114
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 112

def hint
  @hint ||= ('hint')
end

#identifierString

The identifier for this test case. This attempts to be unique, but it might not be.

Returns:

  • (String)

90
91
92
93
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 90

def identifier
  class_name = self.class_name ? self.class_name + '/' : ''
  "#{@test_suite.identifier}/#{class_name}#{name.underscore}"
end

#messagesHash

Combines the different strings above into a hash

Returns:

  • (Hash)

208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 208

def messages
  # prune empty and nil values
  # error_contents and failure_contents are only being stored and not displayed on the interface
  @messages ||= {
    'error': error_message,
    'error_contents': error_contents,
    'hint': hint,
    'failure': failure_message,
    'failure_contents': failure_contents,
    'output': output
  }.reject! { |_, v| v.blank? }
end

#nameString

The name of the test case.

Returns:

  • (String)

73
74
75
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 73

def name
  @test_case['name']
end

#outputString

The output from the function under test. Needs to be initialized by the test code.

Returns:

  • (String)

120
121
122
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 120

def output
  @output ||= ('output')
end

#passed?Boolean

Checks if the test case has passed.

Returns:

  • (Boolean)

201
202
203
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 201

def passed?
  !failed? && !skipped? && !errored?
end

#skipped?Boolean

Checks if the test case was skipped.

Returns:

  • (Boolean)

187
188
189
# File 'lib/autoload/course/assessment/programming_test_case_report.rb', line 187

def skipped?
  !@test_case.search('./skipped').empty?
end