tet 1.0.1

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 +7 -0
  2. data/lib/tests.rb +138 -0
  3. data/lib/tet.rb +120 -0
  4. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c8538e940709458a2b012bc2dd766e96ebf777e3
4
+ data.tar.gz: bccb7511f9807a82cb48273cf5d4362893dc5de3
5
+ SHA512:
6
+ metadata.gz: bff380979ec127635aeade7c8f8be9b25446bf03719d7b4118be09ec4d62a33554d6503abd99d0a4033b9a68767c04ea3bfa87750d6899f6de54100a5f7b8bf7
7
+ data.tar.gz: 6242caf9a43dd9989c055c30c6cde2509594fc7aeaff327b2c6c46548afc322e1abec12c78d5896a151187d436e3ac075c190efeaa780bda1cf0b46fd9f7a96c
data/lib/tests.rb ADDED
@@ -0,0 +1,138 @@
1
+ # Copyright (C) 2016 Colin Fulton
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the
5
+ # terms of the three-clause BSD license. See LICENSE.txt
6
+ # (located in root directory of this project) for details.
7
+
8
+ require_relative './tet'
9
+
10
+ puts 'EXPECTED Results:'
11
+ puts '.....F!F!FF.F......F.F.F.'
12
+ puts 'ACTUAL Results:'
13
+
14
+ group 'Passing' do
15
+ group '#assert' do
16
+ group 'truthy blocks pass' do
17
+ assert { 'this is truthy' }
18
+ end
19
+ end
20
+
21
+ group '#deny' do
22
+ group 'falsy blocks pass' do
23
+ deny { nil }
24
+ end
25
+ end
26
+
27
+ group '#err' do
28
+ group 'passes when there is an error' do
29
+ err { not_a_method }
30
+ end
31
+
32
+ group 'allows you to specify an exception class' do
33
+ err(NameError) { not_a_method }
34
+ end
35
+
36
+ group 'allows you to specify a parent exception class' do
37
+ err(Exception) { not_a_method }
38
+ end
39
+ end
40
+ end
41
+
42
+ group 'Failing' do
43
+ group '#assert' do
44
+ group 'falsy blocks fail' do
45
+ assert { nil }
46
+ end
47
+
48
+ group 'errors are caught and count as failures' do
49
+ assert { not_a_method }
50
+ end
51
+ end
52
+
53
+ group '#deny' do
54
+ group 'truthy blocks fail' do
55
+ deny { 'this is truthy' }
56
+ end
57
+
58
+ group 'errors are caught and count as failures' do
59
+ deny { not_a_method }
60
+ end
61
+ end
62
+
63
+ group '#err' do
64
+ group 'fails when there is no error' do
65
+ err { 1 + 1 }
66
+ end
67
+
68
+ group 'fails given wrong error class' do
69
+ err(ArgumentError) { not_a_method }
70
+ end
71
+ end
72
+ end
73
+
74
+ group 'Output' do
75
+ group '#group' do
76
+ group 'returns output of block' do
77
+ assert do
78
+ group('EXAMPLE') {'example ouput'} == 'example ouput'
79
+ end
80
+ end
81
+
82
+ group 'this test fails to see what giving a Class as name looks like' do
83
+ group String do
84
+ assert { false }
85
+ end
86
+ end
87
+ end
88
+
89
+ # Test if the output of a block is a given Class.
90
+ # Wraps the block in a group to label it as an example instead of a real test.
91
+ def output_is_a? klass
92
+ result = nil
93
+
94
+ group('EXAMPLE') { result = yield }
95
+
96
+ result.is_a?(klass)
97
+ end
98
+
99
+ group 'passing returns true' do
100
+ group '#assert' do
101
+ assert do
102
+ output_is_a?(TrueClass) { assert {"this passes"} }
103
+ end
104
+ end
105
+
106
+ group '#deny' do
107
+ assert do
108
+ output_is_a?(TrueClass) { deny {nil} }
109
+ end
110
+ end
111
+
112
+ group '#err' do
113
+ assert do
114
+ output_is_a?(TrueClass) { err {not_a_method} }
115
+ end
116
+ end
117
+ end
118
+
119
+ group 'failing returns false' do
120
+ group '#assert' do
121
+ assert do
122
+ output_is_a?(FalseClass) { assert {nil} }
123
+ end
124
+ end
125
+
126
+ group '#deny' do
127
+ assert do
128
+ output_is_a?(FalseClass) { deny {"this fails"} }
129
+ end
130
+ end
131
+
132
+ group '#err' do
133
+ assert do
134
+ output_is_a?(FalseClass) { err {"this fails"} }
135
+ end
136
+ end
137
+ end
138
+ end
data/lib/tet.rb ADDED
@@ -0,0 +1,120 @@
1
+ # Copyright (C) 2016 Colin Fulton
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the
5
+ # terms of the three-clause BSD license. See LICENSE.txt
6
+ # (located in root directory of this project) for details.
7
+
8
+ # Label all tests within a block.
9
+ def group name
10
+ Tet.in_group(name) { yield }
11
+ end
12
+
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.
15
+ def assert
16
+ result = false
17
+
18
+ begin
19
+ result = yield
20
+
21
+ if result
22
+ Tet.pass
23
+ else
24
+ Tet.fail
25
+ end
26
+ rescue StandardError => error
27
+ Tet.error(error)
28
+ end
29
+
30
+ !!result
31
+ end
32
+
33
+ # Declare that a block will return a falsy value.
34
+ # If it doesn't or if it has an error, the assertion will be logged as failing.
35
+ def deny
36
+ assert { !yield }
37
+ end
38
+
39
+ # Declare that a block will have an error.
40
+ # 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)
53
+ end
54
+ end
55
+
56
+ result
57
+ end
58
+
59
+ # A namespace for all of the helper methods.
60
+ module Tet
61
+ @current_group = []
62
+ @fail_messeges = []
63
+ @total_asserts = 0
64
+
65
+ class << self
66
+ # Store the group name for the duration of calling the given block.
67
+ def in_group name
68
+ @current_group.push(name)
69
+ yield.tap { @current_group.pop }
70
+ end
71
+
72
+ # Log a passing assertion.
73
+ def pass
74
+ print '.'
75
+
76
+ @total_asserts +=1
77
+ end
78
+
79
+ # Log a failing assertion.
80
+ def fail *messeges, letter: 'F'
81
+ print letter
82
+
83
+ @total_asserts +=1
84
+ @fail_messeges << [@current_group.join(' : '), *messeges].join("\n")
85
+ end
86
+
87
+ # Log an assertion error.
88
+ def error error
89
+ fail format_error(error), letter: '!'
90
+ end
91
+
92
+ # Log an assertion which had the wrong error.
93
+ def wrong_error expected:, got:
94
+ fail indent("EXPECTED: #{expected}", 1),
95
+ format_error(got)
96
+ end
97
+
98
+ private
99
+
100
+ def format_error error
101
+ indent("ERROR: (#{error.class}) #{error.message}", 1) +
102
+ "\n" +
103
+ indent(error.backtrace.join("\n"), 2)
104
+ end
105
+
106
+ def indent string, amount = 0
107
+ string.gsub(/(?<=\n|\A)/, ' ' * amount)
108
+ end
109
+ end
110
+
111
+ # Print messages for all the failing assertions.
112
+ at_exit do
113
+ puts "\n" unless @total_asserts.zero?
114
+ puts "#{@fail_messeges.size} out of #{@total_asserts} failed"
115
+
116
+ @fail_messeges.each do |message|
117
+ puts indent('- ' + message, 1)
118
+ end
119
+ end
120
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tet
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Colin Fulton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A very minimal test framework designed for simple projects. A couple
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.
16
+ email: justcolin@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/tests.rb
22
+ - lib/tet.rb
23
+ homepage: https://github.com/justcolin/tet
24
+ licenses:
25
+ - BSD-3-Clause
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 2.1.3
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.2.2
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Barely a test framework
47
+ test_files: []