test_bench-bootstrap 1.0.0.preview → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/test_bench/bootstrap.rb +41 -30
  3. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa4d5648ba0703a152ffd1708f5146923287cca1f7941adad6ba3163e027d417
4
- data.tar.gz: c8a67629f1ee3a5b4951e7ec049249486fa080d2b91197dab7b867e9c8bddaad
3
+ metadata.gz: ce89e18ca0c6494f546f09c4b8786d7aca2e2bdc435c74b9a0a6cb2786f86481
4
+ data.tar.gz: bba0af0bcee52f86fbb2e58aaa589d8ba7f847ce8cf0e86e08c0b7d086fc381b
5
5
  SHA512:
6
- metadata.gz: c7b8f6a1e175d06463ada01168825aa95a4eb6e15c7404c6ccbe8e9a0605835460af8196e0ff36f9c6eafc7a46c00b0cf66acb7584658738a6f64e2c4fd52ff7
7
- data.tar.gz: a7a91df5a063c56fd4cbca7a1d638b5e0ec86097c82a220b7f4f7576e7c646166c1e8017a4cf379f181c0b0ad0272433a1df802f811084782b2780b33e19b4e2
6
+ metadata.gz: 7631713647f4c2199926af78af8e509fbb96ba247fcee7c20e6b12cacf48307eb26244acc5b2e9522e40c093e8f5d6d1bba52acec8c47e92db15a50facd32b3d
7
+ data.tar.gz: 88944e3be2c9fdd414fd22a5e8ce18e70fdbe840b2482919a68225c8b43d757d748617bb8086628a890a4b60d35e25a0cf56ccf23d5246143d35c8c0ec6dd261
@@ -1,15 +1,13 @@
1
1
  module TestBench
2
2
  module Bootstrap
3
- def self.activate(receiver=nil)
4
- receiver ||= TOPLEVEL_BINDING.receiver
5
-
6
- receiver.extend(Fixture)
3
+ def self.activate
4
+ Object.include(Fixture)
7
5
  end
8
6
 
9
7
  module Fixture
10
8
  def assert(value)
11
9
  unless value
12
- raise AssertionFailure.build(caller_locations.first)
10
+ raise AssertionFailure.build(caller.first)
13
11
  end
14
12
  end
15
13
 
@@ -27,24 +25,24 @@ module TestBench
27
25
  end
28
26
  end
29
27
 
30
- raise AssertionFailure.build(caller_locations.first)
28
+ raise AssertionFailure.build(caller.first)
31
29
  end
32
30
 
33
31
  def refute(value)
34
32
  if value
35
- raise AssertionFailure.build(caller_locations.first)
33
+ raise AssertionFailure.build(caller.first)
36
34
  end
37
35
  end
38
36
 
39
- def refute_raises(error_class, &block)
37
+ def refute_raises(error_class=nil, &block)
40
38
  block.()
41
39
 
42
- rescue error_class => error
40
+ rescue (error_class || StandardError) => error
43
41
  unless error.instance_of?(error_class)
44
42
  raise error
45
43
  end
46
44
 
47
- raise AssertionFailure.build(caller_locations.first)
45
+ raise AssertionFailure.build(caller.first)
48
46
  end
49
47
 
50
48
  def context(prose=nil, &block)
@@ -105,7 +103,7 @@ module TestBench
105
103
  def fixture(cls, *args, **kwargs, &block)
106
104
  fixture = TestBench::Fixture.(cls, *args, **kwargs, &block)
107
105
 
108
- passed = !fixture.test_run.failed?
106
+ passed = !fixture.test_session.failed?
109
107
 
110
108
  assert(passed)
111
109
  end
@@ -116,42 +114,55 @@ module TestBench
116
114
 
117
115
  omitting = false
118
116
 
119
- error_message = error.full_message(highlight: true, order: :bottom)
117
+ Output.write("\e[1mTraceback\e[22m (most recent call last):", sgr_code: 0x31)
118
+
119
+ rjust_length = error.backtrace.length.to_s.length
120
+
121
+ error.backtrace[1..-1].reverse_each.with_index do |line, index|
122
+ line = line.dup
120
123
 
121
- error_message.each_line.with_index do |line, index|
122
124
  line.chomp!
123
125
 
124
- if line.start_with?("\t") && omit_backtrace_pattern.match?(line)
126
+ if omit_backtrace_pattern.match?(line)
125
127
  if omitting
126
128
  next
127
129
  else
128
130
  omitting = true
129
131
 
130
- indentation = line.index("from ")
132
+ header = index.to_s.gsub(/./, '?').rjust(rjust_length, ' ')
131
133
 
132
- line.slice!(indentation..-1)
133
- line.gsub!(%r{[[:digit:]]}, '?')
134
- line.concat("*omitted*")
135
-
136
- Output.write(line, sgr_codes: [0x2, 0x3, 0x31])
134
+ Output.write("#{header}: *omitted*", sgr_codes: [0x2, 0x3, 0x31], tab_indent: true)
137
135
  end
138
136
  else
139
137
  omitting = false
140
138
 
141
- Output.write(line, sgr_code: 0x31)
139
+ header = index.to_s.rjust(rjust_length, ' ')
140
+
141
+ Output.write("#{header}: #{line}", sgr_code: 0x31, tab_indent: true)
142
142
  end
143
143
  end
144
+
145
+ if error.message.empty?
146
+ if error.instance_of?(RuntimeError)
147
+ Output.write("#{error.backtrace[0]}: \e[1;4munhandled exception\e[24;22m", sgr_code: 0x31)
148
+ return
149
+ end
150
+
151
+ error.message = error.class
152
+ end
153
+
154
+ Output.write("#{error.backtrace[0]} \e[1m#{error} (\e[4m#{error.class}\e[24m)\e[22m", sgr_code: 0x31)
144
155
  end
145
156
  end
146
157
 
147
158
  module Output
148
159
  extend self
149
160
 
150
- def write(text, device: nil, sgr_code: nil, sgr_codes: nil)
151
- indent(text, device: device, sgr_code: sgr_code, sgr_codes: sgr_codes)
161
+ def write(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil)
162
+ indent(text, device: device, sgr_code: sgr_code, sgr_codes: sgr_codes, tab_indent: tab_indent)
152
163
  end
153
164
 
154
- def indent(text, device: nil, sgr_code: nil, sgr_codes: nil, &block)
165
+ def indent(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil, &block)
155
166
  device ||= $stdout
156
167
 
157
168
  unless text.nil?
@@ -165,10 +176,10 @@ module TestBench
165
176
  sgr_code.to_s(16)
166
177
  end
167
178
 
168
- text = "\e[#{sgr_codes * ';'}m#{text}\e[0m"
179
+ text = "\e[#{sgr_codes.join(';')}m#{text}\e[0m"
169
180
  end
170
181
 
171
- text = "#{' ' * indentation}#{text}"
182
+ text = "#{"\t" if tab_indent}#{' ' * indentation}#{text}"
172
183
 
173
184
  device.puts(text)
174
185
  end
@@ -192,10 +203,10 @@ module TestBench
192
203
 
193
204
  class AssertionFailure < RuntimeError
194
205
  def self.build(caller_location=nil)
195
- caller_location ||= caller_locations.first
206
+ caller_location ||= caller(0)
196
207
 
197
208
  instance = new
198
- instance.set_backtrace([caller_location.to_s])
209
+ instance.set_backtrace([caller_location])
199
210
  instance
200
211
  end
201
212
 
@@ -206,7 +217,7 @@ module TestBench
206
217
 
207
218
  class Failure < SystemExit
208
219
  def self.build
209
- new(false)
220
+ new(1, "TestBench::Bootstrap is aborting")
210
221
  end
211
222
  end
212
223
 
@@ -230,7 +241,7 @@ module TestBench
230
241
  file_pattern = File.join(file_pattern, '**/*.rb')
231
242
  end
232
243
 
233
- files = Dir[file_pattern].reject do |file|
244
+ files = Dir.glob(file_pattern).reject do |file|
234
245
  File.basename(file).match?(exclude_file_pattern)
235
246
  end
236
247
 
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_bench-bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.preview
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ladd
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-14 00:00:00.000000000 Z
11
+ date: 2020-08-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email: nathanladd+github@gmail.com
15
15
  executables: []
16
16
  extensions: []
@@ -21,7 +21,7 @@ homepage: https://github.com/test-bench/test-bench-bootstrap
21
21
  licenses:
22
22
  - MIT
23
23
  metadata: {}
24
- post_install_message:
24
+ post_install_message:
25
25
  rdoc_options: []
26
26
  require_paths:
27
27
  - lib
@@ -32,12 +32,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
32
32
  version: '0'
33
33
  required_rubygems_version: !ruby/object:Gem::Requirement
34
34
  requirements:
35
- - - ">"
35
+ - - ">="
36
36
  - !ruby/object:Gem::Version
37
- version: 1.3.1
37
+ version: '0'
38
38
  requirements: []
39
- rubygems_version: 3.0.1
40
- signing_key:
39
+ rubygems_version: 3.1.4
40
+ signing_key:
41
41
  specification_version: 4
42
42
  summary: A minimal test framework for testing TestBench
43
43
  test_files: []