Module: TestBench::Structure
- Defined in:
- lib/test_bench/structure.rb
Class Method Summary collapse
Instance Method Summary collapse
- #assert(subject, mod = nil, assert_class: nil, caller_location: nil, &block) ⇒ Object
- #comment(prose) ⇒ Object
- #context(prose = nil, suppress_exit: nil, &block) ⇒ Object
- #refute(*arguments, &block) ⇒ Object
- #test(prose = nil, &block) ⇒ Object
Class Method Details
.error(error, binding) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/test_bench/structure.rb', line 80 def self.error error, binding telemetry = Telemetry::Registry.get binding settings = Settings::Registry.get binding telemetry.error_raised error exit 1 if settings.abort_on_error end |
Instance Method Details
#assert(subject, mod = nil, assert_class: nil, caller_location: nil, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/test_bench/structure.rb', line 3 def assert subject, mod=nil, assert_class: nil, caller_location: nil, &block assert_class ||= Assert caller_location ||= caller_locations[0] telemetry = Telemetry::Registry.get binding unless assert_class.(subject, mod, &block) raise Assert::Failed.build caller_location end ensure telemetry.asserted end |
#comment(prose) ⇒ Object
17 18 19 20 21 |
# File 'lib/test_bench/structure.rb', line 17 def comment prose telemetry = Telemetry::Registry.get binding telemetry.commented prose end |
#context(prose = nil, suppress_exit: nil, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/test_bench/structure.rb', line 23 def context prose=nil, suppress_exit: nil, &block suppress_exit ||= false telemetry = Telemetry::Registry.get binding unless prose.nil? or prose.is_a? String raise TypeError, "Prose must be a String" end begin telemetry.context_entered prose block.() if block rescue => error Structure.error error, binding ensure nesting = telemetry.context_exited prose if nesting.zero? and telemetry.failed? exit 1 unless suppress_exit end end end |
#refute(*arguments, &block) ⇒ Object
48 49 50 |
# File 'lib/test_bench/structure.rb', line 48 def refute *arguments, &block assert(*arguments, :assert_class => Assert::Refute, :caller_location => caller_locations[0], &block) end |
#test(prose = nil, &block) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/test_bench/structure.rb', line 52 def test prose=nil, &block telemetry = Telemetry::Registry.get binding prose ||= 'Test' unless prose.is_a? String raise TypeError, "Prose must be a String" end if block.nil? telemetry.test_skipped prose return end begin telemetry.test_started prose block.() telemetry.test_passed prose rescue => error telemetry.test_failed prose Structure.error error, binding ensure telemetry.test_finished prose end end |