Class: Mumukit::Metatest::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/mumukit/metatest/checker.rb

Direct Known Subclasses

InteractiveChecker

Instance Method Summary collapse

Instance Method Details

#abort(message, details: nil) ⇒ Object



85
86
87
# File 'lib/mumukit/metatest/checker.rb', line 85

def abort(message, details: nil)
  raise Mumukit::Metatest::Aborted.new(message, details)
end

#build_error_output(builder, _example, input, error) ⇒ Object

Implementors should override this method if they want access to the error details and produce more complex test results



67
68
69
# File 'lib/mumukit/metatest/checker.rb', line 67

def build_error_output(builder, _example, input, error)
  builder.result = render_error_output input, error.message
end

#build_failed_test_result(builder, example, input, e) ⇒ Object



100
101
102
103
104
105
# File 'lib/mumukit/metatest/checker.rb', line 100

def build_failed_test_result(builder, example, input, e)
  builder.title = example[:name]
  builder.status = :failed
  build_error_output builder, example, input, e
  builder.build
end

#build_passed_test_result(builder, example, input) ⇒ Object



93
94
95
96
97
98
# File 'lib/mumukit/metatest/checker.rb', line 93

def build_passed_test_result(builder, example, input)
  builder.title = example[:name]
  builder.status = :passed
  build_success_output builder, example, input
  builder.build
end

#build_success_output(builder, _example, input) ⇒ Object

Implementors should override this method if they want access to the error details and produce more complex test results



61
62
63
# File 'lib/mumukit/metatest/checker.rb', line 61

def build_success_output(builder, _example, input)
  builder.result = render_success_output input
end

#check(input, example) ⇒ Object

Check an input against a metatest example. The example has the following shape:

“‘ {

name: 'an example name',
postconditions: {
  an_assertion: assertion_config,
  another_assertion: assertion_config,
}

} “‘

Alternatively, the ‘postconditions` key may be omitted:

“‘

name: 'an example name',
an_assertion: assertion_config,
another_assertion: assertion_config,



26
27
28
29
30
31
32
33
# File 'lib/mumukit/metatest/checker.rb', line 26

def check(input, example)
  builder = Mumukit::Metatest::TestResultBuilder.new

  check_assertions input, postconditions_for(example), example
  build_passed_test_result builder, example, input
rescue => e
  build_failed_test_result builder, example, input, e
end

#check_assertion(assertion_name, input, assertion_config, _example) ⇒ Object



77
78
79
# File 'lib/mumukit/metatest/checker.rb', line 77

def check_assertion(assertion_name, input, assertion_config, _example)
  send "check_#{assertion_name}", input, assertion_config
end

#check_assertions(input, assertions_hash, example) ⇒ Object



71
72
73
74
75
# File 'lib/mumukit/metatest/checker.rb', line 71

def check_assertions(input, assertions_hash, example)
  assertions_hash.each do |assertion_name, assertion_config|
    check_assertion assertion_name, input, assertion_config, example
  end
end

#error(message, details: nil) ⇒ Object



89
90
91
# File 'lib/mumukit/metatest/checker.rb', line 89

def error(message, details: nil)
  raise Mumukit::Metatest::Errored.new(message, details)
end

#fail(message, details: nil) ⇒ Object



81
82
83
# File 'lib/mumukit/metatest/checker.rb', line 81

def fail(message, details: nil)
  raise Mumukit::Metatest::Failed.new(message, details)
end

#postconditions_for(example) ⇒ Object

If no postconditions are included in the example, all the example except by the name is considered as postconditions



37
38
39
# File 'lib/mumukit/metatest/checker.rb', line 37

def postconditions_for(example)
  example[:postconditions] || example.except(:name)
end

#render_error_output(_input, error_message) ⇒ Object

Implementors may override this method instead of ‘build_error_output` if they don’t want to handle error details.

This method is only for backward compatibility. New code should use ‘build_error_output`.



55
56
57
# File 'lib/mumukit/metatest/checker.rb', line 55

def render_error_output(_input, error_message)
  error_message
end

#render_success_output(_input) ⇒ Object

Implementors may override this method instead of ‘build_success_output` if they don’t want to handle error details.

This method is only for backward compatibility. New code should use ‘build_success_output`.



46
47
48
# File 'lib/mumukit/metatest/checker.rb', line 46

def render_success_output(_input)
  nil
end