tet 1.1.0 → 1.2.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tests.rb +54 -48
  3. data/lib/tet.rb +36 -27
  4. metadata +2 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77d0239f2921f33e38b177f8c80d34a3b81ae1f1
4
- data.tar.gz: b6122266f7d0d5bee82c9e76a761b39994228989
3
+ metadata.gz: f2de0d206de213821dee31d262b4fe42fce252ec
4
+ data.tar.gz: 89d73965972497b3b25fe0991cb81311dff1ce6d
5
5
  SHA512:
6
- metadata.gz: 76b1653b796d3eb7c581eddcc057e7e80e9919e7840c7e2a6add135a223860bb88a751c4d0811dc8e7d2a6f3a54aa7b585f79909edfb6f98642d7e3be18532d2
7
- data.tar.gz: 9eb495447fef64e050bc0c4b83c0adf42e07bd6729136cfea8b7808b3b0bd6306cf5510ab1d9af8b3b94373a6f5faf391c362c58b7a0c54950ddd628a8cc1359
6
+ metadata.gz: 67ff1d3932a9f0c12b25f9c98d6abe18502ceb2ae8961c58c7b59bc2c09812b8a56d591a119815f51d23aee376d7100671047af4288cd2c4a16b9bf2971ac55d
7
+ data.tar.gz: 4426a2c64c71c5b14709b059c3486cfec984d059a7d860561a1f6dcef07a51803352dbb9365000077839787fc1f126614e81fac2ca79011b8b077b649b274564
data/lib/tests.rb CHANGED
@@ -7,55 +7,65 @@
7
7
 
8
8
  require_relative "./tet"
9
9
 
10
- puts <<-END
11
- Expected results:
12
- .F!..F.F.F!..F.F.!.F.......FF.FF.F!
13
- 16 out of 35 failed
10
+ $missed_fails = 0
11
+ $missed_errs = 0
12
+ $expected_fails = 0
13
+ $expected_errs = 0
14
+
15
+ at_exit do
16
+ puts <<~END
17
+ \n
18
+ #{$missed_fails} missed fails
19
+ #{$missed_errs} missed errs
20
+ #{total_fails - $expected_fails + $missed_fails} unintended fails
21
+ #{total_errs - $expected_errs + $missed_errs} unintended errs
22
+ END
23
+ end
24
+
25
+ def total_fails
26
+ Tet.data[:fails] - Tet.data[:errs]
27
+ end
14
28
 
15
- Actual results:
16
- END
29
+ def total_errs
30
+ Tet.data[:errs]
31
+ end
17
32
 
18
33
  # Wraps the block in a group to label it as an example instead of a real test.
19
- def fails
34
+ def should_fail
35
+ $expected_fails += 1
36
+ prev_fail_count = total_fails
37
+ result = false
38
+
20
39
  group("INTENDED FAILURE") { result = yield }
21
- end
22
40
 
23
- group "#assert" do
24
- assert("truthy blocks pass") { true }
41
+ $missed_fails += 1 if prev_fail_count == total_fails
25
42
 
26
- fails do
27
- assert("falsy blocks fail") { nil }
28
- assert("errors are caught and count as failures") { not_a_method }
29
- end
43
+ result
44
+ end
30
45
 
31
- assert "passing returns true" do
32
- assert { true }.equal?(true)
33
- end
46
+ # Wraps the block in a group to label it as an example instead of a real test.
47
+ def should_err
48
+ $expected_errs += 1
49
+ prev_err_count = total_errs
50
+ result = false
34
51
 
35
- assert "failing returns false" do
36
- fails { assert { nil }.equal?(false) }
37
- end
52
+ group("INTENDED ERROR") { result = yield }
38
53
 
39
- fails { assert("Can have a name") { nil } }
40
- end
54
+ $missed_errs += 1 if prev_err_count == total_errs
41
55
 
42
- group "#deny" do
43
- deny("falsey blocks pass") { nil }
56
+ result
57
+ end
44
58
 
45
- fails do
46
- deny("truthy blocks fail") { :truthy }
47
- deny("errors are caught and count as failures") { not_a_method }
48
- end
59
+ group "#assert" do
60
+ assert("truthy blocks pass") { true }
49
61
 
50
- assert "passing returns true" do
51
- deny { nil }.equal?(true)
52
- end
62
+ should_fail { assert("falsy blocks fail") { nil } }
63
+ should_err { assert("errors are caught and count as failures") { not_a_method } }
53
64
 
54
- assert "failing returns false" do
55
- fails { deny { :truthy }.equal?(false) }
56
- end
65
+ assert("passing returns true") { true }.equal?(true)
57
66
 
58
- fails { deny("Can have a name") { :truthy } }
67
+ should_fail { assert("failing returns false") { nil }.equal?(false) }
68
+ should_fail { assert("Can have a name") { nil } }
59
69
  end
60
70
 
61
71
  group "#group" do
@@ -63,15 +73,15 @@ group "#group" do
63
73
  group("EXAMPLE") { "example ouput" } == "example ouput"
64
74
  end
65
75
 
66
- return_value = fails { group("catches errors") { raise "Example Error" } }
76
+ return_value = should_err { group { raise "Example Error" } }
67
77
 
68
- assert "returns nil when an assertion returns an error" do
78
+ assert "returns nil when the block throws an error" do
69
79
  return_value.nil?
70
80
  end
71
81
 
72
82
  group "can have classes for names" do
73
83
  group String do
74
- fails { assert { false } }
84
+ should_fail { assert { false } }
75
85
  end
76
86
  end
77
87
  end
@@ -98,24 +108,20 @@ group "#err" do
98
108
  end
99
109
 
100
110
  group "fails when there is no error" do
101
- fails { err { 1+1 } }
111
+ should_fail { err { 1+1 } }
102
112
 
103
113
  assert "... and returns false" do
104
- fails { err { 1+1 } }.equal?(false)
114
+ should_fail { err { 1+1 } }.equal?(false)
105
115
  end
106
116
  end
107
117
 
108
- group "fails given wrong error class" do
109
- fails { err(expect: ArgumentError) { not_a_method } }
118
+ group "ail sgiven wrong error class" do
119
+ should_fail { err(expect: ArgumentError) { not_a_method } }
110
120
 
111
121
  assert "... and returns false" do
112
- fails { err(expect: ArgumentError) { not_a_method } }.equal?(false)
122
+ should_fail { err(expect: ArgumentError) { not_a_method } }.equal?(false)
113
123
  end
114
124
  end
115
125
 
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 } }
126
+ should_fail { err("Can have a name") { 1+1 } }
121
127
  end
data/lib/tet.rb CHANGED
@@ -11,7 +11,7 @@ def group name = nil
11
11
  end
12
12
 
13
13
  # Declare that a block will return a truthy value.
14
- # If it doesn't or if it has an error, the assertion will be logged as failing.
14
+ # If it doesn't or if it has an error, the test will be logged as failing.
15
15
  def assert name = nil
16
16
  Tet.in_group(name) do
17
17
  result = false
@@ -24,22 +24,16 @@ def assert name = nil
24
24
  else
25
25
  Tet.fail
26
26
  end
27
- rescue StandardError => error
28
- Tet.error(error)
27
+ rescue StandardError => error_object
28
+ Tet.error(error_object)
29
29
  end
30
30
 
31
31
  !!result
32
32
  end
33
33
  end
34
34
 
35
- # Declare that a block will return a falsy value.
36
- # If it doesn't or if it has an error, the assertion will be logged as failing.
37
- def deny name = nil
38
- assert(name) { !yield }
39
- end
40
-
41
35
  # Declare that a block will have an error.
42
- # If it doesn't the assertion will be logged as failing.
36
+ # If it doesn't the test will be logged as failing.
43
37
  def err name = nil, expect: StandardError
44
38
  Tet.in_group(name) do
45
39
  result = false
@@ -68,11 +62,16 @@ module Tet
68
62
  GroupSeperator = " | "
69
63
 
70
64
  @current_group = []
71
- @fail_messeges = []
72
- @total_asserts = 0
73
- @total_fails = 0
65
+ @data = {
66
+ messages: [],
67
+ tests: 0,
68
+ fails: 0,
69
+ errs: 0
70
+ }
74
71
 
75
72
  class << self
73
+ attr_reader :data
74
+
76
75
  # Store the group name for the duration of calling the given block.
77
76
  def in_group name
78
77
  result = nil
@@ -88,32 +87,47 @@ module Tet
88
87
  result
89
88
  end
90
89
 
91
- # Log a passing assertion.
90
+ # Log a passing test.
92
91
  def pass
93
92
  print PassChar
94
93
 
95
- @total_asserts += 1
94
+ @data[:tests] += 1
96
95
  end
97
96
 
98
- # Log a failing assertion.
97
+ # Log a failing test.
99
98
  def fail *messeges, letter: FailChar
100
99
  print letter
101
100
 
102
- @total_asserts += 1
103
- @total_fails += 1
104
- @fail_messeges << @current_group.join(GroupSeperator) << messeges
101
+ @data[:tests] += 1
102
+ @data[:fails] += 1
103
+
104
+ @data[:messages] << @current_group.join(GroupSeperator) << messeges
105
105
  end
106
106
 
107
- # Log an assertion error.
107
+ # Log an error.
108
108
  def error error_object, *messages
109
+ @data[:errs] += 1
109
110
  fail *messages, *format_error(error_object), letter: ErrorChar
110
111
  end
111
112
 
112
- # Log an assertion which had the wrong error.
113
+ # Log test which raised the wrong error.
113
114
  def wrong_error expected:, got:
114
115
  fail "EXPECTED: #{expected}", *format_error(got)
115
116
  end
116
117
 
118
+ # Print stats and messages for all the failing tests.
119
+ def render_result
120
+ puts "\n" unless @data[:tests] == 0
121
+
122
+ if @data[:fails] + @data[:errs] == 0
123
+ puts "all #{@data[:tests]} tests passed"
124
+ else
125
+ puts "#{@data[:fails]} fails including #{@data[:errs]} errors"
126
+ end
127
+
128
+ puts indent(@data[:messages])
129
+ end
130
+
117
131
  private
118
132
 
119
133
  # Format an error message so #indent will render it properly
@@ -138,10 +152,5 @@ module Tet
138
152
  end
139
153
  end
140
154
 
141
- # Print messages for all the failing assertions.
142
- at_exit do
143
- puts "\n" unless @total_asserts.zero?
144
- puts "#{@total_fails} out of #{@total_asserts} failed"
145
- puts indent(@fail_messeges)
146
- end
155
+ at_exit { Tet.render_result }
147
156
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.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-05-26 00:00:00.000000000 Z
11
+ date: 2016-06-05 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
@@ -45,4 +45,3 @@ signing_key:
45
45
  specification_version: 4
46
46
  summary: Barely a test framework
47
47
  test_files: []
48
- has_rdoc: