Class: Mxrb::Functional::Suite
- Inherits:
-
Object
- Object
- Mxrb::Functional::Suite
- Defined in:
- lib/mxrb/functional.rb
Overview
Ruby-only definition of runtime microflow tests.
Instance Attribute Summary collapse
-
#tests ⇒ Object
readonly
Returns the value of attribute tests.
Instance Method Summary collapse
- #definition ⇒ Object
- #evaluate(path) ⇒ Object
-
#initialize ⇒ Suite
constructor
A new instance of Suite.
- #microflow(name, call:, pass: {}, timeout: 60, expect: {}, before: nil, after: nil) ⇒ Object
Constructor Details
#initialize ⇒ Suite
Returns a new instance of Suite.
43 44 45 |
# File 'lib/mxrb/functional.rb', line 43 def initialize @tests = [] end |
Instance Attribute Details
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
41 42 43 |
# File 'lib/mxrb/functional.rb', line 41 def tests @tests end |
Instance Method Details
#definition ⇒ Object
73 74 75 |
# File 'lib/mxrb/functional.rb', line 73 def definition Definition.new(@tests.dup.freeze) end |
#evaluate(path) ⇒ Object
68 69 70 71 |
# File 'lib/mxrb/functional.rb', line 68 def evaluate(path) instance_eval(File.read(path), path, 1) self end |
#microflow(name, call:, pass: {}, timeout: 60, expect: {}, before: nil, after: nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mxrb/functional.rb', line 47 def microflow(name, call:, pass: {}, timeout: 60, expect: {}, before: nil, after: nil) label = name.to_s.strip target = call.to_s.strip raise ArgumentError, "functional test name cannot be empty" if label.empty? unless target.match?(/\A[A-Za-z_][A-Za-z0-9_]*\.[A-Za-z_][A-Za-z0-9_]*\z/) raise ArgumentError, "microflow call must be a qualified Mendix name" end raise ArgumentError, "functional test timeout must be positive" unless timeout.to_f.positive? arguments = pass.to_h.transform_keys(&:to_s).transform_values(&:to_s).freeze expectations = expect.to_h expected_return = expectations[:return] || expectations["return"] counts = normalize_counts(expectations[:count] || expectations["count"]) @tests << TestCase.new( label, target, arguments, timeout.to_f, expected_return&.to_s, counts, normalize_hook(before), normalize_hook(after) ) self end |