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 ⇒ Object
- #context(title = nil, &block) ⇒ Object (also: #context!)
- #detail(detail, *additional_details, quote: nil, heading: nil) ⇒ 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 ⇒ Object
154 155 156 |
# File 'lib/test_bench/bootstrap.rb', line 154 def comment(...) detail(...) 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(detail, *additional_details, quote: nil, heading: nil) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/test_bench/bootstrap.rb', line 158 def detail(detail, *additional_details, quote: nil, heading: nil) details = [detail, *additional_details] if quote.nil? if additional_details == [''] quote = true else quote = details.last.end_with?("\n") end end if quote if heading.nil? heading = !detail.end_with?("\n") end end if heading heading_text = details.shift Output.indent(heading_text, sgr_codes: [0x1, 0x4]) end details.each do |detail| if detail.empty? Output.indent("\e[2;3m(empty)\e[23;22m") next end if quote detail.each_line do |line| line.chomp! Output.indent("\e[2m> \e[22m#{line}") end else Output.indent(detail) end end end |
#fixture(cls, *args, **kwargs, &block) ⇒ Object
198 199 200 201 202 203 204 |
# File 'lib/test_bench/bootstrap.rb', line 198 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 |