Module: Tina4::Testing
- Defined in:
- lib/tina4/testing.rb
Defined Under Namespace
Classes: TestContext, TestFailure, TestSuite
Class Method Summary collapse
-
.assert_equal(args, expected) ⇒ Object
Assertion builder: assert_equal(args, expected).
-
.assert_false(args) ⇒ Object
Assertion builder: assert_false(args).
-
.assert_raises(exception_class, args) ⇒ Object
Assertion builder: assert_raises(exception_class, args).
-
.assert_true(args) ⇒ Object
Assertion builder: assert_true(args).
- .describe(name, &block) ⇒ Object
- .inline_registry ⇒ Object
- .reset! ⇒ Object
- .results ⇒ Object
- .run_all(quiet: false, failfast: false) ⇒ Object
- .suites ⇒ Object
-
.tests(*assertions, name: nil, &block) ⇒ Object
Register a callable with inline assertions (mirrors Python’s @tests decorator).
Class Method Details
.assert_equal(args, expected) ⇒ Object
Assertion builder: assert_equal(args, expected)
46 47 48 |
# File 'lib/tina4/testing.rb', line 46 def assert_equal(args, expected) { type: :equal, args: args, expected: expected } end |
.assert_false(args) ⇒ Object
Assertion builder: assert_false(args)
61 62 63 |
# File 'lib/tina4/testing.rb', line 61 def assert_false(args) { type: :false, args: args } end |
.assert_raises(exception_class, args) ⇒ Object
Assertion builder: assert_raises(exception_class, args)
51 52 53 |
# File 'lib/tina4/testing.rb', line 51 def assert_raises(exception_class, args) { type: :raises, exception: exception_class, args: args } end |
.assert_true(args) ⇒ Object
Assertion builder: assert_true(args)
56 57 58 |
# File 'lib/tina4/testing.rb', line 56 def assert_true(args) { type: :true, args: args } end |
.describe(name, &block) ⇒ Object
22 23 24 25 26 |
# File 'lib/tina4/testing.rb', line 22 def describe(name, &block) suite = TestSuite.new(name) suite.instance_eval(&block) suites << suite end |
.inline_registry ⇒ Object
82 83 84 |
# File 'lib/tina4/testing.rb', line 82 def inline_registry @inline_registry ||= [] end |
.reset! ⇒ Object
16 17 18 19 20 |
# File 'lib/tina4/testing.rb', line 16 def reset! @suites = [] @inline_registry = [] @results = { passed: 0, failed: 0, errors: 0, tests: [] } end |
.results ⇒ Object
12 13 14 |
# File 'lib/tina4/testing.rb', line 12 def results @results ||= { passed: 0, failed: 0, errors: 0, tests: [] } end |
.run_all(quiet: false, failfast: false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tina4/testing.rb', line 28 def run_all(quiet: false, failfast: false) reset_results suites.each do |suite| run_suite(suite, quiet: quiet, failfast: failfast) break if failfast && results[:failed] > 0 end # Run inline-registered tests inline_registry.each do |entry| run_inline_entry(entry, quiet: quiet) break if failfast && results[:failed] > 0 end print_results unless quiet results end |
.suites ⇒ Object
8 9 10 |
# File 'lib/tina4/testing.rb', line 8 def suites @suites ||= [] end |
.tests(*assertions, name: nil, &block) ⇒ Object
Register a callable with inline assertions (mirrors Python’s @tests decorator).
Tina4::Testing.tests(
Tina4::Testing.assert_equal([5, 3], 8),
Tina4::Testing.assert_raises(ArgumentError, [nil]),
) { |a, b| raise ArgumentError, "b required" if b.nil?; a + b }
72 73 74 75 76 77 78 79 80 |
# File 'lib/tina4/testing.rb', line 72 def tests(*assertions, name: nil, &block) raise ArgumentError, "tests requires a block" unless block_given? inline_registry << { fn: block, name: name || "anonymous", assertions: assertions } block end |