Class: Mumukit::Metatest::Checker
- Inherits:
-
Object
- Object
- Mumukit::Metatest::Checker
- Defined in:
- lib/mumukit/metatest/checker.rb
Direct Known Subclasses
Instance Method Summary collapse
- #abort(message) ⇒ Object
-
#check(input, example) ⇒ Object
Check an input against a metatest example.
- #check_assertion(assertion_name, input, assertion_config, _example) ⇒ Object
- #check_assertions(input, assertions_hash, example) ⇒ Object
- #error(message) ⇒ Object
- #fail(message) ⇒ Object
-
#postconditions_for(example) ⇒ Object
If no postconditions are included in the example, all the example except by the name is considered as postconditions.
- #render_error_output(value, error) ⇒ Object
- #render_success_output(value) ⇒ Object
Instance Method Details
#abort(message) ⇒ Object
61 62 63 |
# File 'lib/mumukit/metatest/checker.rb', line 61 def abort() raise Mumukit::Metatest::Aborted, 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 |
# File 'lib/mumukit/metatest/checker.rb', line 26 def check(input, example) check_assertions input, postconditions_for(example), example [example[:name], :passed, render_success_output(input)] rescue => e [example[:name], :failed, render_error_output(input, e.)] end |
#check_assertion(assertion_name, input, assertion_config, _example) ⇒ Object
53 54 55 |
# File 'lib/mumukit/metatest/checker.rb', line 53 def check_assertion(assertion_name, input, assertion_config, _example) send "check_#{assertion_name}", input, assertion_config end |
#check_assertions(input, assertions_hash, example) ⇒ Object
47 48 49 50 51 |
# File 'lib/mumukit/metatest/checker.rb', line 47 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) ⇒ Object
65 66 67 |
# File 'lib/mumukit/metatest/checker.rb', line 65 def error() raise Mumukit::Metatest::Errored, end |
#fail(message) ⇒ Object
57 58 59 |
# File 'lib/mumukit/metatest/checker.rb', line 57 def fail() raise Mumukit::Metatest::Failed, end |
#postconditions_for(example) ⇒ Object
If no postconditions are included in the example, all the example except by the name is considered as postconditions
35 36 37 |
# File 'lib/mumukit/metatest/checker.rb', line 35 def postconditions_for(example) example[:postconditions] || example.except(:name) end |
#render_error_output(value, error) ⇒ Object
43 44 45 |
# File 'lib/mumukit/metatest/checker.rb', line 43 def render_error_output(value, error) error end |
#render_success_output(value) ⇒ Object
39 40 41 |
# File 'lib/mumukit/metatest/checker.rb', line 39 def render_success_output(value) nil end |