Module: TestBench::Bootstrap::Fixture
- Defined in:
- lib/test_bench/bootstrap.rb
Instance Method Summary collapse
- #_context(title = nil, &block) ⇒ Object
- #_test(title = nil, &block) ⇒ Object
- #assert(value) ⇒ Object
- #assert_raises(error_class = nil, &block) ⇒ Object
- #comment(text) ⇒ Object
- #context(title = nil, &block) ⇒ Object (also: #context!)
- #detail(text) ⇒ Object
- #fixture(cls, *args, **kwargs, &block) ⇒ Object
- #refute(value) ⇒ Object
- #refute_raises(error_class = nil, &block) ⇒ Object
- #test(title = nil, &block) ⇒ Object (also: #test!)
Instance Method Details
#_context(title = nil, &block) ⇒ Object
127 128 129 |
# File 'lib/test_bench/bootstrap.rb', line 127 def _context(title=nil, &block) context(title) end |
#_test(title = nil, &block) ⇒ Object
150 151 152 |
# File 'lib/test_bench/bootstrap.rb', line 150 def _test(title=nil, &block) test(title) end |
#assert(value) ⇒ Object
70 71 72 73 74 |
# File 'lib/test_bench/bootstrap.rb', line 70 def assert(value) unless value raise AssertionFailure.build(1) end end |
#assert_raises(error_class = nil, &block) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/test_bench/bootstrap.rb', line 76 def assert_raises(error_class=nil, &block) begin block.() rescue (error_class || StandardError) => error return if error_class.nil? if error.instance_of?(error_class) return else raise error end end raise AssertionFailure.build(1) end |
#comment(text) ⇒ Object
154 155 156 |
# File 'lib/test_bench/bootstrap.rb', line 154 def comment(text) Output.write(text) end |
#context(title = nil, &block) ⇒ Object Also known as: context!
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/test_bench/bootstrap.rb', line 110 def context(title=nil, &block) if block.nil? Output.write(title || 'Context', sgr_code: 0x33) return end unless title.nil? Output.indent(title, sgr_code: 0x32) do context(&block) end return end block.() end |
#detail(text) ⇒ Object
158 159 160 |
# File 'lib/test_bench/bootstrap.rb', line 158 def detail(text) comment(text) end |
#fixture(cls, *args, **kwargs, &block) ⇒ Object
162 163 164 165 166 167 168 |
# File 'lib/test_bench/bootstrap.rb', line 162 def fixture(cls, *args, **kwargs, &block) fixture = TestBench::Fixture.(cls, *args, **kwargs, &block) passed = !fixture.test_session.failed? assert(passed) end |
#refute(value) ⇒ Object
93 94 95 96 97 |
# File 'lib/test_bench/bootstrap.rb', line 93 def refute(value) if value raise AssertionFailure.build(1) end end |
#refute_raises(error_class = nil, &block) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/test_bench/bootstrap.rb', line 99 def refute_raises(error_class=nil, &block) block.() rescue (error_class || StandardError) => error unless error.instance_of?(error_class) raise error end raise AssertionFailure.build(1) end |
#test(title = nil, &block) ⇒ Object Also known as: test!
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/test_bench/bootstrap.rb', line 131 def test(title=nil, &block) if block.nil? Output.write(title || 'Test', sgr_code: 0x33) return end begin block.() Output.indent(title, sgr_code: 0x32) rescue => error Output.indent(title || 'Test', sgr_codes: [0x1, 0x31]) raise error end end |