probatio 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/LICENSE.txt +24 -0
- data/README.md +13 -0
- data/exe/proba +16 -0
- data/lib/probatio.rb +394 -0
- data/probatio.gemspec +54 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a2ad9b151150b2a112358c58b0a480d72eaba65a400ae8a6a21e54d74e61136e
|
4
|
+
data.tar.gz: d2d008237d2133169b56dedd842e72c27efc760caa2ddf13d95d232e6c5b6197
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ceb178be47b755d00d0bedb8f16087d983b3e5ab61afa1c7b22d366ecd8f3646edb231f70f840cf2a3ce65b744991802b087b9806e9f385d009d6fbf60ca76fe
|
7
|
+
data.tar.gz: b1845474c38066483e226dfbd87ef75697ab0d39a2deaf9b550229ab9000744b3906f1e133b453804e5d02148b5252a5f79e691ad09c27d44ca804d496fc72c4
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2024-2025, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
21
|
+
|
22
|
+
|
23
|
+
Made in Japan
|
24
|
+
|
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
# probatio
|
3
|
+
|
4
|
+
<!-- [](https://github.com/floraison/fugit/actions) -->
|
5
|
+
[](https://badge.fury.io/rb/probatio)
|
6
|
+
|
7
|
+
Test tools for floraison and flor. Somewhere between Minitest and Rspec, but not as excellent.
|
8
|
+
|
9
|
+
|
10
|
+
## LICENSE
|
11
|
+
|
12
|
+
MIT, see [LICENSE.txt](LICENSE.txt)
|
13
|
+
|
data/exe/proba
ADDED
data/lib/probatio.rb
ADDED
@@ -0,0 +1,394 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# probatio.rb
|
4
|
+
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
|
8
|
+
module Probatio
|
9
|
+
|
10
|
+
VERSION = '0.9.0'
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def run(run_opts)
|
15
|
+
|
16
|
+
Probatio.despatch(:start, run_opts)
|
17
|
+
|
18
|
+
root_group = Group.new(nil, '_', {}, __FILE__, nil)
|
19
|
+
|
20
|
+
dir = run_opts[:dir]
|
21
|
+
|
22
|
+
Dir[File.join(dir, '**', '*_helper.rb')].each do |path|
|
23
|
+
|
24
|
+
read_helper_file(root_group, path)
|
25
|
+
end
|
26
|
+
|
27
|
+
Dir[File.join(dir, '**', '*_test.rb')].each do |path|
|
28
|
+
|
29
|
+
read_test_file(root_group, path)
|
30
|
+
end
|
31
|
+
|
32
|
+
root_group.run(run_opts)
|
33
|
+
|
34
|
+
Probatio.despatch(:over, run_opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
def init
|
38
|
+
|
39
|
+
@plugins = []
|
40
|
+
end
|
41
|
+
|
42
|
+
def plugins; @plugins; end
|
43
|
+
|
44
|
+
def plug(x)
|
45
|
+
|
46
|
+
@plugins << x
|
47
|
+
end
|
48
|
+
|
49
|
+
def despatch(event_name, *details)
|
50
|
+
|
51
|
+
#p [ :despatch, event_name ]
|
52
|
+
m = "on_#{event_name}"
|
53
|
+
ev = Probatio::Event.new(event_name.to_sym, details)
|
54
|
+
|
55
|
+
@plugins.each do |plugin|
|
56
|
+
plugin.send(m, ev) if plugin.respond_to?(m)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
|
62
|
+
def read_helper_file(group, path)
|
63
|
+
|
64
|
+
Kernel.load(path)
|
65
|
+
end
|
66
|
+
|
67
|
+
def read_test_file(group, path)
|
68
|
+
|
69
|
+
group.add_file(path)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
self.init
|
74
|
+
|
75
|
+
class Group
|
76
|
+
|
77
|
+
attr_reader :name
|
78
|
+
attr_accessor :path
|
79
|
+
|
80
|
+
def initialize(parent_group, name, group_opts, path, block)
|
81
|
+
|
82
|
+
@parent = parent_group
|
83
|
+
|
84
|
+
@name = name
|
85
|
+
@group_opts = group_opts
|
86
|
+
@path = path
|
87
|
+
|
88
|
+
@children = []
|
89
|
+
|
90
|
+
add_block(block)
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_block(block)
|
94
|
+
|
95
|
+
instance_eval(&block) if block
|
96
|
+
end
|
97
|
+
|
98
|
+
def add_file(path)
|
99
|
+
|
100
|
+
@path = path
|
101
|
+
|
102
|
+
instance_eval(File.read(path))
|
103
|
+
end
|
104
|
+
|
105
|
+
def to_s(opts={})
|
106
|
+
|
107
|
+
out = opts[:out] || StringIO.new
|
108
|
+
ind = opts[:indent] || ''
|
109
|
+
gos = @group_opts.any? ? ' ' + @group_opts.inspect : ''
|
110
|
+
|
111
|
+
out <<
|
112
|
+
"#{ind}group #{@name.inspect}#{gos}\n"
|
113
|
+
|
114
|
+
@children.each do |c|
|
115
|
+
c.to_s(opts.merge(out: out, indent: ind + ' '))
|
116
|
+
end unless opts[:head]
|
117
|
+
|
118
|
+
opts[:out] ? nil : out.string
|
119
|
+
end
|
120
|
+
|
121
|
+
def head; to_s(head: true); end
|
122
|
+
|
123
|
+
def run(run_opts)
|
124
|
+
|
125
|
+
# on_group_enter, on_group_leave
|
126
|
+
# on_test_leave
|
127
|
+
# on_setup, on_teardown
|
128
|
+
# on_before, on_after
|
129
|
+
Probatio.despatch(:group_enter, self)
|
130
|
+
|
131
|
+
setups.each { |s| s.run(run_opts) }
|
132
|
+
|
133
|
+
tests.each do |t|
|
134
|
+
|
135
|
+
c = Probatio::Context.new(self)
|
136
|
+
|
137
|
+
befores.each { |b| c.run(b, run_opts) }
|
138
|
+
|
139
|
+
c.run(t, run_opts)
|
140
|
+
|
141
|
+
afters.each { |a| c.run(a, run_opts) }
|
142
|
+
end
|
143
|
+
|
144
|
+
groups.each { |g| g.run(run_opts) }
|
145
|
+
|
146
|
+
teardowns.each { |s| s.run(run_opts) }
|
147
|
+
|
148
|
+
Probatio.despatch(:group_leave, self)
|
149
|
+
end
|
150
|
+
|
151
|
+
def setup(opts={}, &block)
|
152
|
+
@children << Probatio::Setup.new(self, nil, opts, @path, block)
|
153
|
+
end
|
154
|
+
def teardown(opts={}, &block)
|
155
|
+
@children << Probatio::Teardown.new(self, nil, opts, @path, block)
|
156
|
+
end
|
157
|
+
def before(opts={}, &block)
|
158
|
+
@children << Probatio::Before.new(self, nil, opts, @path, block)
|
159
|
+
end
|
160
|
+
def after(opts={}, &block)
|
161
|
+
@children << Probatio::After.new(self, nil, opts, @path, block)
|
162
|
+
end
|
163
|
+
|
164
|
+
def group(name, opts={}, &block)
|
165
|
+
|
166
|
+
if g = @children.find { |e| e.is_a?(Probatio::Group) && e.name == name }
|
167
|
+
g.path = @path
|
168
|
+
g.add_block(block)
|
169
|
+
else
|
170
|
+
@children << Probatio::Group.new(self, name, opts, @path, block)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def test(name, opts={}, &block)
|
175
|
+
|
176
|
+
@children << Probatio::Test.new(self, name, opts, @path, block)
|
177
|
+
end
|
178
|
+
|
179
|
+
def befores
|
180
|
+
|
181
|
+
(@parent ? @parent.befores : []) +
|
182
|
+
@children.select { |c| c.is_a?(Probatio::Before) }
|
183
|
+
end
|
184
|
+
|
185
|
+
def afters
|
186
|
+
|
187
|
+
(@parent ? @parent.afters : []) +
|
188
|
+
@children.select { |c| c.is_a?(Probatio::After) }
|
189
|
+
end
|
190
|
+
|
191
|
+
ATTRS = %i[ @parent @name @group_opts @path @children ].freeze
|
192
|
+
|
193
|
+
def context(h={})
|
194
|
+
|
195
|
+
instance_variables
|
196
|
+
.each { |k|
|
197
|
+
h[k] = instance_variable_get(k) unless ATTRS.include?(k) }
|
198
|
+
@parent.context(h) if @parent
|
199
|
+
|
200
|
+
h
|
201
|
+
end
|
202
|
+
|
203
|
+
protected
|
204
|
+
|
205
|
+
def setups; @children.select { |c| c.is_a?(Probatio::Setup) }; end
|
206
|
+
def teardowns; @children.select { |c| c.is_a?(Probatio::Teardown) }; end
|
207
|
+
|
208
|
+
def test_and_groups
|
209
|
+
@children.select { |c|
|
210
|
+
c.is_a?(Probatio::Test) || c.is_a?(Probatio::Group) }
|
211
|
+
end
|
212
|
+
def tests; @children.select { |c| c.is_a?(Probatio::Test) }; end
|
213
|
+
def groups; @children.select { |c| c.is_a?(Probatio::Group) }; end
|
214
|
+
end
|
215
|
+
|
216
|
+
class Child
|
217
|
+
|
218
|
+
attr_reader :name, :opts, :block
|
219
|
+
|
220
|
+
def initialize(parent, name, opts, path, block)
|
221
|
+
|
222
|
+
@parent = parent
|
223
|
+
@name = name
|
224
|
+
@opts = opts
|
225
|
+
@path = path
|
226
|
+
@block = block
|
227
|
+
end
|
228
|
+
|
229
|
+
def type
|
230
|
+
|
231
|
+
self.class.name.split('::').last.downcase
|
232
|
+
end
|
233
|
+
|
234
|
+
def to_s(opts={})
|
235
|
+
|
236
|
+
n = @name ? ' ' + @name.inspect : ''
|
237
|
+
os = @opts.any? ? ' ' + @opts.inspect : ''
|
238
|
+
_, l = block.source_location
|
239
|
+
|
240
|
+
(opts[:out] || $stdout) <<
|
241
|
+
"#{opts[:indent]}#{type}#{n}#{os} #{@path}:#{l}\n"
|
242
|
+
end
|
243
|
+
|
244
|
+
def run(run_opts)
|
245
|
+
|
246
|
+
Probatio.despatch("#{type}_enter", self)
|
247
|
+
|
248
|
+
@parent.instance_eval(&@block)
|
249
|
+
|
250
|
+
Probatio.despatch("#{type}_leave", self)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
class Setup < Child; end
|
255
|
+
class Teardown < Child; end
|
256
|
+
|
257
|
+
class Before < Child; end
|
258
|
+
class After < Child; end
|
259
|
+
|
260
|
+
class Test < Child; end
|
261
|
+
|
262
|
+
class Context
|
263
|
+
|
264
|
+
def initialize(group)
|
265
|
+
|
266
|
+
group.context.each { |k, v| instance_variable_set(k, v) }
|
267
|
+
end
|
268
|
+
|
269
|
+
def run(child, run_opts)
|
270
|
+
|
271
|
+
@__child = child
|
272
|
+
|
273
|
+
Probatio.despatch("#{child.type}_enter", self, child, run_opts)
|
274
|
+
|
275
|
+
instance_eval(&child.block)
|
276
|
+
|
277
|
+
rescue AssertionError => aerr
|
278
|
+
ensure
|
279
|
+
Probatio.despatch("#{child.type}_leave", self, child, run_opts)
|
280
|
+
end
|
281
|
+
|
282
|
+
def assert(*as)
|
283
|
+
|
284
|
+
do_assert do
|
285
|
+
|
286
|
+
as.all? { |a| a == as[0] } ||
|
287
|
+
"no equal"
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
def assert_match(*as)
|
292
|
+
|
293
|
+
do_assert do
|
294
|
+
|
295
|
+
strings, others = as.partition { |a| a.is_a?(String) }
|
296
|
+
rex = others.find { |o| o.is_a?(Regexp) } || strings.pop
|
297
|
+
|
298
|
+
strings.all? { |s| s.match?(rex) } ||
|
299
|
+
"no match"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
protected
|
304
|
+
|
305
|
+
def do_assert(&block)
|
306
|
+
|
307
|
+
r =
|
308
|
+
begin
|
309
|
+
block.call
|
310
|
+
rescue => err
|
311
|
+
err
|
312
|
+
end
|
313
|
+
|
314
|
+
if r.is_a?(StandardError) || r.is_a?(String)
|
315
|
+
|
316
|
+
Probatio.despatch(:test_succeed, self, @__child)
|
317
|
+
|
318
|
+
fail AssertionError.new(r)
|
319
|
+
|
320
|
+
elsif r.is_a?(Exception)
|
321
|
+
|
322
|
+
raise r
|
323
|
+
end
|
324
|
+
|
325
|
+
Probatio.despatch(:test_fail, self, @__child)
|
326
|
+
|
327
|
+
true # end on a positive note...
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
class AssertionError < StandardError
|
332
|
+
|
333
|
+
attr_accessor :nested_error
|
334
|
+
|
335
|
+
def initialize(error_or_message)
|
336
|
+
|
337
|
+
if error_or_message.is_a?(String)
|
338
|
+
super(message)
|
339
|
+
else
|
340
|
+
super("error while asserting: " + error_or_message.message)
|
341
|
+
@nested_error = error_or_message
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
class Event
|
347
|
+
|
348
|
+
attr_reader :name, :opts, :context, :group, :child
|
349
|
+
|
350
|
+
def initialize(name, details)
|
351
|
+
|
352
|
+
@name = name
|
353
|
+
|
354
|
+
details.each do |d|
|
355
|
+
case d
|
356
|
+
when Hash then @opts = d
|
357
|
+
when Probatio::Group then @group = d
|
358
|
+
when Probatio::Child then @child = d
|
359
|
+
when Probatio::Context then @context = d
|
360
|
+
else fail ArgumentError.new("cannot fathom #{d.class} #{d.inspect}")
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
module Probatio::DotReporter
|
368
|
+
|
369
|
+
class << self
|
370
|
+
|
371
|
+
def on_start(ev)
|
372
|
+
|
373
|
+
@successes = []
|
374
|
+
@failures = []
|
375
|
+
end
|
376
|
+
|
377
|
+
def on_test_succeed(ev)
|
378
|
+
print '.'
|
379
|
+
@successes << ev
|
380
|
+
end
|
381
|
+
|
382
|
+
def on_test_fail(ev)
|
383
|
+
print 'x'
|
384
|
+
@failures << ev
|
385
|
+
end
|
386
|
+
|
387
|
+
def on_over(ev)
|
388
|
+
puts
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
Probatio.plug(Probatio::DotReporter)
|
394
|
+
|
data/probatio.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
|
4
|
+
s.name = 'probatio'
|
5
|
+
|
6
|
+
s.version = File.read(
|
7
|
+
File.expand_path('../lib/probatio.rb', __FILE__)
|
8
|
+
).match(/ VERSION *= *['"]([^'"]+)/)[1]
|
9
|
+
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = [ 'John Mettraux' ]
|
12
|
+
s.email = [ 'jmettraux+flor@gmail.com' ]
|
13
|
+
s.homepage = 'https://github.com/floraison/fugit'
|
14
|
+
s.license = 'MIT'
|
15
|
+
s.summary = 'test tools for floraison and flor'
|
16
|
+
|
17
|
+
s.description = %{
|
18
|
+
Test tools for floraison and flor. Somewhere between Minitest and Rspec, but not as excellent.
|
19
|
+
}.strip
|
20
|
+
|
21
|
+
s.metadata = {
|
22
|
+
'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.md',
|
23
|
+
'bug_tracker_uri' => s.homepage + '/issues',
|
24
|
+
'documentation_uri' => s.homepage,
|
25
|
+
'homepage_uri' => s.homepage,
|
26
|
+
'source_code_uri' => s.homepage,
|
27
|
+
#'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/floraison',
|
28
|
+
#'wiki_uri' => s.homepage + '/wiki',
|
29
|
+
'rubygems_mfa_required' => 'true',
|
30
|
+
}
|
31
|
+
|
32
|
+
#s.files = `git ls-files`.split("\n")
|
33
|
+
s.files = Dir[
|
34
|
+
'{README,CHANGELOG,CREDITS,LICENSE}.{md,txt}',
|
35
|
+
#'Makefile',
|
36
|
+
'lib/**/*.rb', #'spec/**/*.rb', 'test/**/*.rb',
|
37
|
+
'exe/*',
|
38
|
+
"#{s.name}.gemspec",
|
39
|
+
]
|
40
|
+
|
41
|
+
#s.add_runtime_dependency 'tzinfo'
|
42
|
+
# this dependency appears in 'et-orbi'
|
43
|
+
|
44
|
+
s.add_runtime_dependency 'colorato', '~> 1.0'
|
45
|
+
|
46
|
+
#s.add_development_dependency 'rspec', '~> 3.8'
|
47
|
+
# ;-)
|
48
|
+
|
49
|
+
s.require_path = 'lib'
|
50
|
+
|
51
|
+
s.bindir = 'exe'
|
52
|
+
s.executables = [ 'proba' ]
|
53
|
+
end
|
54
|
+
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: probatio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Mettraux
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorato
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: Test tools for floraison and flor. Somewhere between Minitest and Rspec,
|
28
|
+
but not as excellent.
|
29
|
+
email:
|
30
|
+
- jmettraux+flor@gmail.com
|
31
|
+
executables:
|
32
|
+
- proba
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- CHANGELOG.md
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- exe/proba
|
40
|
+
- lib/probatio.rb
|
41
|
+
- probatio.gemspec
|
42
|
+
homepage: https://github.com/floraison/fugit
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata:
|
46
|
+
changelog_uri: https://github.com/floraison/fugit/blob/master/CHANGELOG.md
|
47
|
+
bug_tracker_uri: https://github.com/floraison/fugit/issues
|
48
|
+
documentation_uri: https://github.com/floraison/fugit
|
49
|
+
homepage_uri: https://github.com/floraison/fugit
|
50
|
+
source_code_uri: https://github.com/floraison/fugit
|
51
|
+
rubygems_mfa_required: 'true'
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.5.16
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: test tools for floraison and flor
|
71
|
+
test_files: []
|