u-test 0.7.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/microtest.rb +105 -0
- data/test_runners.rb +35 -0
- data/u-test.rb +3 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a1ac17b72f4257a8511f88bd8d2fc64cb3fbb5f6b89346513753d14c468a3b57
|
4
|
+
data.tar.gz: b1f8466076b4488b214dfbeda14f1c91a95a62c0b2c8489f6be0881e7d8930f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7bce28f44f44666a73704ac6851b2a79e5c4980b516e8e5f99d3bf9d959788675463edb3386c45eaeaffb726f8e0fe24fafbb8f170dd6c189c1a59ff5812a898
|
7
|
+
data.tar.gz: d0deb86939a031a5dcace6b878a20e2280c0949202135f9dcdd4191b4d2878bb5a12e4c5317ad607ed75955a2b2b4b9d05f6547bfb641285ad43916aa2e26be9
|
data/microtest.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
module Microtest
|
7
|
+
VERSION = '0.7.0'
|
8
|
+
|
9
|
+
TryToBuildARandom = -> (seed, randomized) do
|
10
|
+
Random.new Integer(seed ? seed : rand(1000..99999)) if seed || randomized
|
11
|
+
end
|
12
|
+
|
13
|
+
class Runner
|
14
|
+
include Singleton
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@test_cases = Set.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def register(test_case)
|
21
|
+
@test_cases.add(test_case) and true
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(random:)
|
25
|
+
iterate_each_test_after_try_to_shuffle(random) do |test, test_methods|
|
26
|
+
test.call(:setup_all)
|
27
|
+
|
28
|
+
test_methods.each do |test_method|
|
29
|
+
test.call(:setup, test_method)
|
30
|
+
test.call(test_method)
|
31
|
+
test.call(:teardown, test_method)
|
32
|
+
end
|
33
|
+
|
34
|
+
test.call(:teardown_all)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def iterate_each_test_after_try_to_shuffle(random)
|
41
|
+
shuffle_if_random(@test_cases, random).each do |test_case|
|
42
|
+
test_methods = test_case.public_instance_methods.grep(/\Atest_/)
|
43
|
+
|
44
|
+
yield method(:call_test).curry[test_case.new],
|
45
|
+
shuffle_if_random(test_methods, random)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def call_test(test_case, method_to_call, method_arg = nil)
|
50
|
+
return unless test_case.respond_to?(method_to_call)
|
51
|
+
method = test_case.method(method_to_call)
|
52
|
+
method.arity == 0 ? method.call : method.call(method_arg)
|
53
|
+
end
|
54
|
+
|
55
|
+
def shuffle_if_random(relation, random)
|
56
|
+
random ? relation.to_a.shuffle(random: random) : relation
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Test
|
61
|
+
def self.inherited(test_case)
|
62
|
+
Runner.instance.register(test_case)
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.test(name, &block)
|
66
|
+
method = "test_#{name.gsub(/\s+/,'_')}"
|
67
|
+
raise "#{method} is already defined in #{self}" if method_defined?(method)
|
68
|
+
define_method(method, &block)
|
69
|
+
end
|
70
|
+
|
71
|
+
def assert(test, msg = '%s is not truthy.')
|
72
|
+
stop!(test, caller, msg) unless test
|
73
|
+
end
|
74
|
+
|
75
|
+
def refute(test, msg = '%s is neither nil or false.')
|
76
|
+
stop!(test, caller, msg) if test
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def stop!(test, kaller, msg)
|
82
|
+
message = msg % test.inspect
|
83
|
+
caller_location = kaller[0].split('/').last
|
84
|
+
raise RuntimeError, message, [caller_location]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.report(randomized = nil, out:)
|
89
|
+
random = TryToBuildARandom.call(ENV['SEED'], randomized)
|
90
|
+
|
91
|
+
yield -> { Runner.instance.call(random: random) }
|
92
|
+
|
93
|
+
out.puts "\n\e[#{32}m\u{1f60e} Tests passed!\e[0m\n\n"
|
94
|
+
rescue => e
|
95
|
+
content = ["\u{1f4a9} <#{e.class}> #{e.message}\n", e.backtrace.join("\n")]
|
96
|
+
|
97
|
+
out.puts ["\e[#{31}m", content, "\e[0m"].flatten.join("\n")
|
98
|
+
ensure
|
99
|
+
out.puts "Randomized with seed: #{random.seed}\n\n" if random.is_a?(Random)
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.call(randomized: false, out: Kernel)
|
103
|
+
report(randomized, out: out) { |runner| runner.call }
|
104
|
+
end
|
105
|
+
end
|
data/test_runners.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class RunRubyProgram
|
4
|
+
LINE_CHAR = '#'
|
5
|
+
|
6
|
+
def self.line(command)
|
7
|
+
(LINE_CHAR * command.size) + LINE_CHAR * 4
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.cmd(file)
|
11
|
+
yield "ruby #{file}.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.render_cmd(file)
|
15
|
+
cmd(file) do |command|
|
16
|
+
puts line(command)
|
17
|
+
puts "#{LINE_CHAR} #{command} #{LINE_CHAR}"
|
18
|
+
puts line(command)
|
19
|
+
|
20
|
+
yield(command) if block_given?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.call(file)
|
25
|
+
render_cmd(file) { |command| system(command) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
RunRubyProgram.call('test_runner')
|
30
|
+
|
31
|
+
RunRubyProgram.call('test_runner_to_assert_a_random_execution')
|
32
|
+
|
33
|
+
RunRubyProgram.call('test_runner_to_assert_an_execution_in_sequence')
|
34
|
+
|
35
|
+
RunRubyProgram.call('test_runner_to_assert_microtest_outputs')
|
data/u-test.rb
ADDED
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: u-test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodrigo Serradura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A xUnit family unit testing microframework for Ruby.
|
14
|
+
email: rodrigo.serradura@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- microtest.rb
|
20
|
+
- test_runners.rb
|
21
|
+
- u-test.rb
|
22
|
+
homepage: https://gist.github.com/serradura/d26f7f322977e35dd508c8c13a9179b1
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- "."
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.2.2
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.7.7
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: A unit testing microframework
|
46
|
+
test_files:
|
47
|
+
- test_runners.rb
|