Class: Capsium::Package::Testing::TestCase
- Inherits:
-
Object
- Object
- Capsium::Package::Testing::TestCase
- Defined in:
- lib/capsium/package/testing/test_case.rb,
sig/capsium/package/testing/test_case.rbs
Overview
Base class for one test of the Capsium testing YAML DSL (05x-testing). Subclasses implement a test kind and register themselves under their DSL type name (open/closed registry).
Direct Known Subclasses
Defined Under Namespace
Classes: DefinitionError, Result
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.build(definition) ⇒ TestCase
Builds a test case from a YAML definition hash (string keys).
- .from_h(definition) ⇒ TestCase
- .register(type, klass) ⇒ void
- .types ⇒ Hash[String, singleton(TestCase)]
Instance Method Summary collapse
-
#initialize(name:) ⇒ TestCase
constructor
A new instance of TestCase.
-
#run(context) ⇒ Result
Runs the test against the context and returns a Result.
Constructor Details
#initialize(name:) ⇒ TestCase
Returns a new instance of TestCase.
21 22 23 |
# File 'lib/capsium/package/testing/test_case.rb', line 21 def initialize(name:) @name = name end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/capsium/package/testing/test_case.rb', line 19 def name @name end |
Class Method Details
.build(definition) ⇒ TestCase
Builds a test case from a YAML definition hash (string keys).
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/capsium/package/testing/test_case.rb', line 39 def self.build(definition) unless definition.is_a?(Hash) raise DefinitionError, "test definition is not a mapping: #{definition.inspect}" end type = definition["type"] || raise(DefinitionError, "test #{definition['name'].inspect} has no type") klass = types[type] || raise(DefinitionError, "unknown test type: #{type}") klass.from_h(definition) rescue ArgumentError => e raise DefinitionError, "invalid #{type} test #{definition['name'].inspect}: #{e.}" end |
.from_h(definition) ⇒ TestCase
52 53 54 55 56 |
# File 'lib/capsium/package/testing/test_case.rb', line 52 def self.from_h(definition) attributes = definition.transform_keys(&:to_sym) attributes.delete(:type) new(**attributes) end |
.register(type, klass) ⇒ void
This method returns an undefined value.
30 31 32 |
# File 'lib/capsium/package/testing/test_case.rb', line 30 def self.register(type, klass) types[type] = klass end |
.types ⇒ Hash[String, singleton(TestCase)]
34 35 36 |
# File 'lib/capsium/package/testing/test_case.rb', line 34 def self.types @types ||= {} end |
Instance Method Details
#run(context) ⇒ Result
Runs the test against the context and returns a Result.
26 27 28 |
# File 'lib/capsium/package/testing/test_case.rb', line 26 def run(context) raise NotImplementedError end |