tet 1.0.5 → 1.1.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 +4 -4
- data/lib/tests.rb +76 -98
- data/lib/tet.rb +61 -40
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77d0239f2921f33e38b177f8c80d34a3b81ae1f1
|
4
|
+
data.tar.gz: b6122266f7d0d5bee82c9e76a761b39994228989
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76b1653b796d3eb7c581eddcc057e7e80e9919e7840c7e2a6add135a223860bb88a751c4d0811dc8e7d2a6f3a54aa7b585f79909edfb6f98642d7e3be18532d2
|
7
|
+
data.tar.gz: 9eb495447fef64e050bc0c4b83c0adf42e07bd6729136cfea8b7808b3b0bd6306cf5510ab1d9af8b3b94373a6f5faf391c362c58b7a0c54950ddd628a8cc1359
|
data/lib/tests.rb
CHANGED
@@ -5,139 +5,117 @@
|
|
5
5
|
# terms of the three-clause BSD license. See LICENSE.txt
|
6
6
|
# (located in root directory of this project) for details.
|
7
7
|
|
8
|
-
require_relative
|
8
|
+
require_relative "./tet"
|
9
9
|
|
10
|
-
puts
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
puts <<-END
|
11
|
+
Expected results:
|
12
|
+
.F!..F.F.F!..F.F.!.F.......FF.FF.F!
|
13
|
+
16 out of 35 failed
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
group 'truthy blocks pass' do
|
18
|
-
assert { 'this is truthy' }
|
19
|
-
end
|
20
|
-
end
|
15
|
+
Actual results:
|
16
|
+
END
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
18
|
+
# Wraps the block in a group to label it as an example instead of a real test.
|
19
|
+
def fails
|
20
|
+
group("INTENDED FAILURE") { result = yield }
|
21
|
+
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
err { not_a_method }
|
31
|
-
end
|
23
|
+
group "#assert" do
|
24
|
+
assert("truthy blocks pass") { true }
|
32
25
|
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
fails do
|
27
|
+
assert("falsy blocks fail") { nil }
|
28
|
+
assert("errors are caught and count as failures") { not_a_method }
|
29
|
+
end
|
36
30
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
31
|
+
assert "passing returns true" do
|
32
|
+
assert { true }.equal?(true)
|
40
33
|
end
|
34
|
+
|
35
|
+
assert "failing returns false" do
|
36
|
+
fails { assert { nil }.equal?(false) }
|
37
|
+
end
|
38
|
+
|
39
|
+
fails { assert("Can have a name") { nil } }
|
41
40
|
end
|
42
41
|
|
43
|
-
group
|
44
|
-
|
45
|
-
group 'falsy blocks fail' do
|
46
|
-
assert { nil }
|
47
|
-
end
|
42
|
+
group "#deny" do
|
43
|
+
deny("falsey blocks pass") { nil }
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
fails do
|
46
|
+
deny("truthy blocks fail") { :truthy }
|
47
|
+
deny("errors are caught and count as failures") { not_a_method }
|
52
48
|
end
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
50
|
+
assert "passing returns true" do
|
51
|
+
deny { nil }.equal?(true)
|
52
|
+
end
|
58
53
|
|
59
|
-
|
60
|
-
|
61
|
-
end
|
54
|
+
assert "failing returns false" do
|
55
|
+
fails { deny { :truthy }.equal?(false) }
|
62
56
|
end
|
63
57
|
|
64
|
-
|
65
|
-
|
66
|
-
err { 1 + 1 }
|
67
|
-
end
|
58
|
+
fails { deny("Can have a name") { :truthy } }
|
59
|
+
end
|
68
60
|
|
69
|
-
|
70
|
-
|
71
|
-
|
61
|
+
group "#group" do
|
62
|
+
assert "returns output of block" do
|
63
|
+
group("EXAMPLE") { "example ouput" } == "example ouput"
|
72
64
|
end
|
73
|
-
end
|
74
65
|
|
75
|
-
group
|
76
|
-
group '#group' do
|
77
|
-
group 'returns output of block' do
|
78
|
-
assert do
|
79
|
-
group('EXAMPLE') {'example ouput'} == 'example ouput'
|
80
|
-
end
|
81
|
-
end
|
66
|
+
return_value = fails { group("catches errors") { raise "Example Error" } }
|
82
67
|
|
83
|
-
|
84
|
-
|
85
|
-
assert { false }
|
86
|
-
end
|
87
|
-
end
|
68
|
+
assert "returns nil when an assertion returns an error" do
|
69
|
+
return_value.nil?
|
88
70
|
end
|
89
71
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
72
|
+
group "can have classes for names" do
|
73
|
+
group String do
|
74
|
+
fails { assert { false } }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
94
78
|
|
95
|
-
|
79
|
+
group "#err" do
|
80
|
+
group "passes when there is an error" do
|
81
|
+
err { not_a_method }
|
96
82
|
|
97
|
-
|
83
|
+
assert "... and returns true" do
|
84
|
+
err { not_a_method }.equal?(true)
|
85
|
+
end
|
98
86
|
end
|
99
87
|
|
100
|
-
group
|
101
|
-
|
102
|
-
assert do
|
103
|
-
output_is_a?(TrueClass) { assert {"this passes"} }
|
104
|
-
end
|
105
|
-
end
|
88
|
+
group "allows you to specify an exception class" do
|
89
|
+
err(expect: NameError) { not_a_method }
|
106
90
|
|
107
|
-
group
|
108
|
-
|
109
|
-
output_is_a?(TrueClass) { deny {nil} }
|
110
|
-
end
|
91
|
+
group "... or a parent exception class" do
|
92
|
+
err(expect: Exception) { not_a_method }
|
111
93
|
end
|
112
94
|
|
113
|
-
|
114
|
-
|
115
|
-
output_is_a?(TrueClass) { err {not_a_method} }
|
116
|
-
end
|
95
|
+
assert "... and returns true" do
|
96
|
+
err(expect: NameError) { not_a_method }.equal?(true)
|
117
97
|
end
|
118
98
|
end
|
119
99
|
|
120
|
-
group
|
121
|
-
|
122
|
-
assert do
|
123
|
-
output_is_a?(FalseClass) { assert {nil} }
|
124
|
-
end
|
125
|
-
end
|
100
|
+
group "fails when there is no error" do
|
101
|
+
fails { err { 1+1 } }
|
126
102
|
|
127
|
-
|
128
|
-
|
129
|
-
output_is_a?(FalseClass) { deny {"this fails"} }
|
130
|
-
end
|
103
|
+
assert "... and returns false" do
|
104
|
+
fails { err { 1+1 } }.equal?(false)
|
131
105
|
end
|
106
|
+
end
|
132
107
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
108
|
+
group "fails given wrong error class" do
|
109
|
+
fails { err(expect: ArgumentError) { not_a_method } }
|
110
|
+
|
111
|
+
assert "... and returns false" do
|
112
|
+
fails { err(expect: ArgumentError) { not_a_method } }.equal?(false)
|
137
113
|
end
|
138
114
|
end
|
139
115
|
|
140
|
-
|
141
|
-
|
142
|
-
|
116
|
+
fails { err("Can have a name") { 1+1 } }
|
117
|
+
end
|
118
|
+
|
119
|
+
group "'Did you mean?' error messages look nice" do
|
120
|
+
fails { assert { 1.to_z } }
|
143
121
|
end
|
data/lib/tet.rb
CHANGED
@@ -6,58 +6,67 @@
|
|
6
6
|
# (located in root directory of this project) for details.
|
7
7
|
|
8
8
|
# Label all tests within a block.
|
9
|
-
def group name
|
9
|
+
def group name = nil
|
10
10
|
Tet.in_group(name) { yield }
|
11
11
|
end
|
12
12
|
|
13
13
|
# Declare that a block will return a truthy value.
|
14
14
|
# If it doesn't or if it has an error, the assertion will be logged as failing.
|
15
|
-
def assert
|
16
|
-
|
15
|
+
def assert name = nil
|
16
|
+
Tet.in_group(name) do
|
17
|
+
result = false
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
begin
|
20
|
+
result = yield
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
if result
|
23
|
+
Tet.pass
|
24
|
+
else
|
25
|
+
Tet.fail
|
26
|
+
end
|
27
|
+
rescue StandardError => error
|
28
|
+
Tet.error(error)
|
25
29
|
end
|
26
|
-
rescue StandardError => error
|
27
|
-
Tet.error(error)
|
28
|
-
end
|
29
30
|
|
30
|
-
|
31
|
+
!!result
|
32
|
+
end
|
31
33
|
end
|
32
34
|
|
33
35
|
# Declare that a block will return a falsy value.
|
34
36
|
# If it doesn't or if it has an error, the assertion will be logged as failing.
|
35
|
-
def deny
|
36
|
-
assert { !yield }
|
37
|
+
def deny name = nil
|
38
|
+
assert(name) { !yield }
|
37
39
|
end
|
38
40
|
|
39
41
|
# Declare that a block will have an error.
|
40
42
|
# If it doesn't the assertion will be logged as failing.
|
41
|
-
def err
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
43
|
+
def err name = nil, expect: StandardError
|
44
|
+
Tet.in_group(name) do
|
45
|
+
result = false
|
46
|
+
|
47
|
+
begin
|
48
|
+
yield
|
49
|
+
Tet.fail
|
50
|
+
rescue StandardError => error_object
|
51
|
+
if expect >= error_object.class
|
52
|
+
result = true
|
53
|
+
Tet.pass
|
54
|
+
else
|
55
|
+
Tet.wrong_error(expected: expect, got: error_object)
|
56
|
+
end
|
53
57
|
end
|
54
|
-
end
|
55
58
|
|
56
|
-
|
59
|
+
result
|
60
|
+
end
|
57
61
|
end
|
58
62
|
|
59
63
|
# A namespace for all of the helper methods.
|
60
64
|
module Tet
|
65
|
+
PassChar = "."
|
66
|
+
FailChar = "F"
|
67
|
+
ErrorChar = "!"
|
68
|
+
GroupSeperator = " | "
|
69
|
+
|
61
70
|
@current_group = []
|
62
71
|
@fail_messeges = []
|
63
72
|
@total_asserts = 0
|
@@ -66,29 +75,38 @@ module Tet
|
|
66
75
|
class << self
|
67
76
|
# Store the group name for the duration of calling the given block.
|
68
77
|
def in_group name
|
69
|
-
|
70
|
-
|
78
|
+
result = nil
|
79
|
+
@current_group.push(name) if name
|
80
|
+
|
81
|
+
begin
|
82
|
+
result = yield
|
83
|
+
rescue StandardError => error_object
|
84
|
+
error error_object, "ERROR IN GROUP"
|
85
|
+
end
|
86
|
+
|
87
|
+
@current_group.pop if name
|
88
|
+
result
|
71
89
|
end
|
72
90
|
|
73
91
|
# Log a passing assertion.
|
74
92
|
def pass
|
75
|
-
print
|
93
|
+
print PassChar
|
76
94
|
|
77
95
|
@total_asserts += 1
|
78
96
|
end
|
79
97
|
|
80
98
|
# Log a failing assertion.
|
81
|
-
def fail *messeges, letter:
|
99
|
+
def fail *messeges, letter: FailChar
|
82
100
|
print letter
|
83
101
|
|
84
102
|
@total_asserts += 1
|
85
103
|
@total_fails += 1
|
86
|
-
@fail_messeges << @current_group.join(
|
104
|
+
@fail_messeges << @current_group.join(GroupSeperator) << messeges
|
87
105
|
end
|
88
106
|
|
89
107
|
# Log an assertion error.
|
90
|
-
def error
|
91
|
-
fail *format_error(
|
108
|
+
def error error_object, *messages
|
109
|
+
fail *messages, *format_error(error_object), letter: ErrorChar
|
92
110
|
end
|
93
111
|
|
94
112
|
# Log an assertion which had the wrong error.
|
@@ -98,17 +116,20 @@ module Tet
|
|
98
116
|
|
99
117
|
private
|
100
118
|
|
101
|
-
|
119
|
+
# Format an error message so #indent will render it properly
|
120
|
+
def format_error error_object
|
102
121
|
[
|
103
|
-
"ERROR: #{
|
104
|
-
["#{
|
122
|
+
"ERROR: #{error_object.class}",
|
123
|
+
["#{error_object.message}", error_object.backtrace]
|
105
124
|
]
|
106
125
|
end
|
107
126
|
|
127
|
+
# Format an array of strings by joining them with \n and indenting nested
|
128
|
+
# arrays deeper than their parents.
|
108
129
|
def indent input, amount = 0
|
109
130
|
case input
|
110
131
|
when String
|
111
|
-
input.gsub(/^/,
|
132
|
+
input.gsub(/^/, " " * amount)
|
112
133
|
when Array
|
113
134
|
input.reject(&:empty?)
|
114
135
|
.map { |part| indent(part, amount + 1) }
|
metadata
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Fulton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A very minimal test framework designed for simple projects. A couple
|
14
14
|
of features, relatively nice looking output, and nothing else. Does the world need
|
15
|
-
another test framework? No. Is Tet the product boredom and yak shaving? Yes.
|
15
|
+
another test framework? No. Is Tet the product of boredom and yak shaving? Yes.
|
16
16
|
email: justcolin@gmail.com
|
17
17
|
executables: []
|
18
18
|
extensions: []
|