tet 1.2.0 → 1.3.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 +22 -11
  3. data/lib/tet.rb +55 -24
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2de0d206de213821dee31d262b4fe42fce252ec
4
- data.tar.gz: 89d73965972497b3b25fe0991cb81311dff1ce6d
3
+ metadata.gz: 449cdabbdb6add0195f4e4c6741f9a6ca2e491b8
4
+ data.tar.gz: 56a1ca4040f22d3c406084a494f05c935555c541
5
5
  SHA512:
6
- metadata.gz: 67ff1d3932a9f0c12b25f9c98d6abe18502ceb2ae8961c58c7b59bc2c09812b8a56d591a119815f51d23aee376d7100671047af4288cd2c4a16b9bf2971ac55d
7
- data.tar.gz: 4426a2c64c71c5b14709b059c3486cfec984d059a7d860561a1f6dcef07a51803352dbb9365000077839787fc1f126614e81fac2ca79011b8b077b649b274564
6
+ metadata.gz: 52e770323c5aba08b74b57ce5bc059de674f9d1dd23d491901d2eedd5910ea1b322733d6fd413ee7eb554984659bd80286c289f73d07fdcb68cd38624d55ea22
7
+ data.tar.gz: 0d3e1b923b7292cff3c613fe5697e26561f9200efd801dd5836ab98834891406f43b4903ce7665ab4a7e5e09363ccf012849ba29cd99b969e94304ed7b9f6513
data/lib/tests.rb CHANGED
@@ -23,11 +23,11 @@ at_exit do
23
23
  end
24
24
 
25
25
  def total_fails
26
- Tet.data[:fails] - Tet.data[:errs]
26
+ Tet.fail_count - Tet.err_count
27
27
  end
28
28
 
29
29
  def total_errs
30
- Tet.data[:errs]
30
+ Tet.err_count
31
31
  end
32
32
 
33
33
  # Wraps the block in a group to label it as an example instead of a real test.
@@ -61,16 +61,21 @@ group "#assert" do
61
61
 
62
62
  should_fail { assert("falsy blocks fail") { nil } }
63
63
  should_err { assert("errors are caught and count as failures") { not_a_method } }
64
+ should_fail { assert("empty assertions fail") {} }
64
65
 
65
- assert("passing returns true") { true }.equal?(true)
66
+ assert("passing returns true") { assert { true }.equal?(true) }
66
67
 
67
68
  should_fail { assert("failing returns false") { nil }.equal?(false) }
68
- should_fail { assert("Can have a name") { nil } }
69
69
  end
70
70
 
71
71
  group "#group" do
72
72
  assert "returns output of block" do
73
- group("EXAMPLE") { "example ouput" } == "example ouput"
73
+ result = group("EXAMPLE") do
74
+ assert("EXAMPLE") { true }
75
+ "example output"
76
+ end
77
+
78
+ result == "example output"
74
79
  end
75
80
 
76
81
  return_value = should_err { group { raise "Example Error" } }
@@ -79,6 +84,10 @@ group "#group" do
79
84
  return_value.nil?
80
85
  end
81
86
 
87
+ group 'fails when empty' do
88
+ should_fail { group { } }
89
+ end
90
+
82
91
  group "can have classes for names" do
83
92
  group String do
84
93
  should_fail { assert { false } }
@@ -90,19 +99,21 @@ group "#err" do
90
99
  group "passes when there is an error" do
91
100
  err { not_a_method }
92
101
 
93
- assert "... and returns true" do
102
+ assert "and returns true" do
94
103
  err { not_a_method }.equal?(true)
95
104
  end
96
105
  end
97
106
 
107
+ should_fail { err("empty assertions fail") {} }
108
+
98
109
  group "allows you to specify an exception class" do
99
110
  err(expect: NameError) { not_a_method }
100
111
 
101
- group "... or a parent exception class" do
112
+ group "or a parent exception class" do
102
113
  err(expect: Exception) { not_a_method }
103
114
  end
104
115
 
105
- assert "... and returns true" do
116
+ assert "and returns true" do
106
117
  err(expect: NameError) { not_a_method }.equal?(true)
107
118
  end
108
119
  end
@@ -110,15 +121,15 @@ group "#err" do
110
121
  group "fails when there is no error" do
111
122
  should_fail { err { 1+1 } }
112
123
 
113
- assert "... and returns false" do
124
+ assert "and returns false" do
114
125
  should_fail { err { 1+1 } }.equal?(false)
115
126
  end
116
127
  end
117
128
 
118
- group "ail sgiven wrong error class" do
129
+ group "fails given wrong error class" do
119
130
  should_fail { err(expect: ArgumentError) { not_a_method } }
120
131
 
121
- assert "... and returns false" do
132
+ assert "and returns false" do
122
133
  should_fail { err(expect: ArgumentError) { not_a_method } }.equal?(false)
123
134
  end
124
135
  end
data/lib/tet.rb CHANGED
@@ -7,7 +7,10 @@
7
7
 
8
8
  # Label all tests within a block.
9
9
  def group name = nil
10
+ before = Tet.test_count
11
+
10
12
  Tet.in_group(name) { yield }
13
+ .tap { Tet.fail "EMPTY GROUP" if Tet.test_count == before }
11
14
  end
12
15
 
13
16
  # Declare that a block will return a truthy value.
@@ -56,26 +59,25 @@ end
56
59
 
57
60
  # A namespace for all of the helper methods.
58
61
  module Tet
59
- PassChar = "."
60
- FailChar = "F"
61
- ErrorChar = "!"
62
- GroupSeperator = " | "
62
+ PassChar = "."
63
+ FailChar = "F"
64
+ ErrorChar = "!"
65
+ Indent = " "
63
66
 
67
+ @messages = []
64
68
  @current_group = []
65
- @data = {
66
- messages: [],
67
- tests: 0,
68
- fails: 0,
69
- errs: 0
70
- }
69
+ @test_count = 0
70
+ @fail_count = 0
71
+ @err_count = 0
71
72
 
72
73
  class << self
73
- attr_reader :data
74
+ attr_reader :messages, :test_count, :fail_count, :err_count
74
75
 
75
76
  # Store the group name for the duration of calling the given block.
76
77
  def in_group name
77
78
  result = nil
78
- @current_group.push(name) if name
79
+
80
+ @current_group << name.to_s if name
79
81
 
80
82
  begin
81
83
  result = yield
@@ -84,6 +86,7 @@ module Tet
84
86
  end
85
87
 
86
88
  @current_group.pop if name
89
+
87
90
  result
88
91
  end
89
92
 
@@ -91,22 +94,35 @@ module Tet
91
94
  def pass
92
95
  print PassChar
93
96
 
94
- @data[:tests] += 1
97
+ @test_count += 1
95
98
  end
96
99
 
97
100
  # Log a failing test.
98
101
  def fail *messeges, letter: FailChar
99
102
  print letter
100
103
 
101
- @data[:tests] += 1
102
- @data[:fails] += 1
104
+ @test_count += 1
105
+ @fail_count += 1
106
+
107
+ group = @current_group.dup
108
+ section = @messages
103
109
 
104
- @data[:messages] << @current_group.join(GroupSeperator) << messeges
110
+ until group.empty? || group.first != section[-2]
111
+ group.shift
112
+ section = section.last
113
+ end
114
+
115
+ until group.empty?
116
+ section << group.shift << []
117
+ section = section.last
118
+ end
119
+
120
+ section.concat(messeges)
105
121
  end
106
122
 
107
123
  # Log an error.
108
124
  def error error_object, *messages
109
- @data[:errs] += 1
125
+ @err_count += 1
110
126
  fail *messages, *format_error(error_object), letter: ErrorChar
111
127
  end
112
128
 
@@ -117,15 +133,23 @@ module Tet
117
133
 
118
134
  # Print stats and messages for all the failing tests.
119
135
  def render_result
120
- puts "\n" unless @data[:tests] == 0
136
+ puts "\n" unless @test_count.zero?
137
+
138
+ print "#{plural @test_count, 'result'}, "
121
139
 
122
- if @data[:fails] + @data[:errs] == 0
123
- puts "all #{@data[:tests]} tests passed"
140
+ if (@fail_count + @err_count).zero?
141
+ print "suite passed!"
124
142
  else
125
- puts "#{@data[:fails]} fails including #{@data[:errs]} errors"
143
+ print "#{plural @fail_count, 'fail'}"
144
+ print " (including #{plural @err_count, 'error'})" unless @err_count.zero?
126
145
  end
127
146
 
128
- puts indent(@data[:messages])
147
+ print "\n"
148
+
149
+ unless @messages.empty?
150
+ puts "\nFailed tests:"
151
+ puts indent(@messages)
152
+ end
129
153
  end
130
154
 
131
155
  private
@@ -134,7 +158,10 @@ module Tet
134
158
  def format_error error_object
135
159
  [
136
160
  "ERROR: #{error_object.class}",
137
- ["#{error_object.message}", error_object.backtrace]
161
+ [
162
+ "#{error_object.message}",
163
+ error_object.backtrace
164
+ ]
138
165
  ]
139
166
  end
140
167
 
@@ -143,13 +170,17 @@ module Tet
143
170
  def indent input, amount = 0
144
171
  case input
145
172
  when String
146
- input.gsub(/^/, " " * amount)
173
+ input.gsub(/^/, Indent * amount)
147
174
  when Array
148
175
  input.reject(&:empty?)
149
176
  .map { |part| indent(part, amount + 1) }
150
177
  .join("\n")
151
178
  end
152
179
  end
180
+
181
+ def plural amount, name
182
+ "#{amount} #{name}#{amount != 1 ? "s" : ""}"
183
+ end
153
184
  end
154
185
 
155
186
  at_exit { Tet.render_result }
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.2.0
4
+ version: 1.3.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-06-05 00:00:00.000000000 Z
11
+ date: 2016-10-30 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