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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tests.rb +76 -98
  3. data/lib/tet.rb +61 -40
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc5e7a16c8fec8cf15d0cc6e7b87c242a2231984
4
- data.tar.gz: 67a7ca617271c9830b8e07a6bb2e572ae90973a1
3
+ metadata.gz: 77d0239f2921f33e38b177f8c80d34a3b81ae1f1
4
+ data.tar.gz: b6122266f7d0d5bee82c9e76a761b39994228989
5
5
  SHA512:
6
- metadata.gz: 934900975f00590e80c56ca2df4daff59449e43d85cda520736557b770f22773ec0d073648dad9f8ac9ad5b958452c28599e6d5d1c9e140a8eb6593c07a92316
7
- data.tar.gz: b9ac41a49766a32206d09a08ed11f02921b4d7003fc55cb17db09eae862754dc8b41818af0172ee99de167a214d9eb0c89b31463539a595b8d0bb852df3ffa6c
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 './tet'
8
+ require_relative "./tet"
9
9
 
10
- puts 'EXPECTED Results:'
11
- puts '.....F!F!FF.F......F.F.F.!'
12
- puts '11 out of 26 failed'
13
- puts "\nACTUAL Results:"
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
- group 'Passing' do
16
- group '#assert' do
17
- group 'truthy blocks pass' do
18
- assert { 'this is truthy' }
19
- end
20
- end
15
+ Actual results:
16
+ END
21
17
 
22
- group '#deny' do
23
- group 'falsy blocks pass' do
24
- deny { nil }
25
- end
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
- group '#err' do
29
- group 'passes when there is an error' do
30
- err { not_a_method }
31
- end
23
+ group "#assert" do
24
+ assert("truthy blocks pass") { true }
32
25
 
33
- group 'allows you to specify an exception class' do
34
- err(NameError) { not_a_method }
35
- end
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
- group 'allows you to specify a parent exception class' do
38
- err(Exception) { not_a_method }
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 'Failing' do
44
- group '#assert' do
45
- group 'falsy blocks fail' do
46
- assert { nil }
47
- end
42
+ group "#deny" do
43
+ deny("falsey blocks pass") { nil }
48
44
 
49
- group 'errors are caught and count as failures' do
50
- assert { not_a_method }
51
- end
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
- group '#deny' do
55
- group 'truthy blocks fail' do
56
- deny { 'this is truthy' }
57
- end
50
+ assert "passing returns true" do
51
+ deny { nil }.equal?(true)
52
+ end
58
53
 
59
- group 'errors are caught and count as failures' do
60
- deny { not_a_method }
61
- end
54
+ assert "failing returns false" do
55
+ fails { deny { :truthy }.equal?(false) }
62
56
  end
63
57
 
64
- group '#err' do
65
- group 'fails when there is no error' do
66
- err { 1 + 1 }
67
- end
58
+ fails { deny("Can have a name") { :truthy } }
59
+ end
68
60
 
69
- group 'fails given wrong error class' do
70
- err(ArgumentError) { not_a_method }
71
- end
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 'Output' do
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
- group 'this test fails to see what giving a Class as name looks like' do
84
- group String do
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
- # Test if the output of a block is a given Class.
91
- # Wraps the block in a group to label it as an example instead of a real test.
92
- def output_is_a? klass
93
- result = nil
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
- group('EXAMPLE') { result = yield }
79
+ group "#err" do
80
+ group "passes when there is an error" do
81
+ err { not_a_method }
96
82
 
97
- result.is_a?(klass)
83
+ assert "... and returns true" do
84
+ err { not_a_method }.equal?(true)
85
+ end
98
86
  end
99
87
 
100
- group 'passing returns true' do
101
- group '#assert' do
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 '#deny' do
108
- assert do
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
- group '#err' do
114
- assert do
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 'failing returns false' do
121
- group '#assert' do
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
- group '#deny' do
128
- assert do
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
- group '#err' do
134
- assert do
135
- output_is_a?(FalseClass) { err {"this fails"} }
136
- end
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
- group '"Did you mean?" messages look nice' do
141
- assert { 1.to_ss }
142
- end
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
- result = false
15
+ def assert name = nil
16
+ Tet.in_group(name) do
17
+ result = false
17
18
 
18
- begin
19
- result = yield
19
+ begin
20
+ result = yield
20
21
 
21
- if result
22
- Tet.pass
23
- else
24
- Tet.fail
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
- !!result
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 expect = StandardError
42
- result = false
43
-
44
- begin
45
- yield
46
- Tet.fail
47
- rescue StandardError => error
48
- if expect >= error.class
49
- result = true
50
- Tet.pass
51
- else
52
- Tet.wrong_error(expected: expect, got: error)
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
- result
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
- @current_group.push(name)
70
- yield.tap { @current_group.pop }
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: 'F'
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(' : ') << messeges
104
+ @fail_messeges << @current_group.join(GroupSeperator) << messeges
87
105
  end
88
106
 
89
107
  # Log an assertion error.
90
- def error error
91
- fail *format_error(error), letter: '!'
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
- def format_error error
119
+ # Format an error message so #indent will render it properly
120
+ def format_error error_object
102
121
  [
103
- "ERROR: #{error.class}",
104
- ["#{error.message}", error.backtrace]
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(/^/, ' ' * amount)
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.5
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-04-11 00:00:00.000000000 Z
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: []