tryouts 2.2.0.pre.RC1 → 2.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.
- checksums.yaml +4 -4
- data/LICENSE.txt +7 -5
- data/README.md +109 -0
- data/exe/try +37 -0
- data/exe/tryouts +4 -0
- data/lib/tryouts/version.rb +13 -0
- data/lib/tryouts.rb +67 -76
- metadata +18 -29
- data/README.rdoc +0 -123
- data/Rakefile +0 -63
- data/bin/try +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 964b15141b2d2a8658bb5beee61ef9618ad478b8c29a4c91c5595dfb7ac92323
|
4
|
+
data.tar.gz: b33744a232df6dd0020deef5ea682217481ba6fc17d6d1336ccb9dc314080052
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4116e1c5918e226ec2232a55cd4dfdc8ff034948ceafa03ca3cdaecee6df4aa2f7d1dc5598eed66074f0c2e22c71492b7fab83c83b8869165897be69cabf4e9c
|
7
|
+
data.tar.gz: 826761b6d51762fb214380d05d438ab70b029bab4c7a138b59909ac096bcdc5bc79d7aed6c6f2509d728b6ea59f8ea03201fb42e6e77002fef1cd47a7635ec7d
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011-2024 Delano Mandelbaum
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -7,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
9
|
copies of the Software, and to permit persons to whom the Software is
|
8
10
|
furnished to do so, subject to the following conditions:
|
9
11
|
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
11
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
12
14
|
|
13
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Tryouts v2.3.0 (2024-04-04)
|
2
|
+
|
3
|
+
**Ruby tests that read like documentation.**
|
4
|
+
|
5
|
+
A simple test framework for Ruby code that uses introspection to allow defining checks in comments.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
One of:
|
10
|
+
* In your Gemfile: `gem 'tryouts'`
|
11
|
+
* As a gem: `gem install tryouts`
|
12
|
+
* From source:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
$ git clone git://github.com/tryouts/tryouts.git
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
```bash
|
21
|
+
# Run all tests accessible from the current directory (e.g. ./try, ./tryouts))
|
22
|
+
$ try
|
23
|
+
|
24
|
+
# Run a single test file
|
25
|
+
$ try try/10_utils_try.rb
|
26
|
+
|
27
|
+
# Command arguments
|
28
|
+
$ try -h
|
29
|
+
Usage: try [options]
|
30
|
+
-V, --version Display the version
|
31
|
+
-q, --quiet Run in quiet mode
|
32
|
+
-v, --verbose Run in verbose mode
|
33
|
+
-f, --fails Show only failing tryouts
|
34
|
+
-D, --debug Run in debug mode
|
35
|
+
-h, --help Display this help
|
36
|
+
```
|
37
|
+
|
38
|
+
### Exit codes
|
39
|
+
|
40
|
+
When all tests pass, try exits with a 0. An exit code of 1 or more indicates the number of failing tests.
|
41
|
+
|
42
|
+
|
43
|
+
## Writing tests
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
## A very simple test
|
47
|
+
1 + 1
|
48
|
+
#=> 2
|
49
|
+
|
50
|
+
## The test description can spread
|
51
|
+
## across multiple lines. The same
|
52
|
+
## is true for test definitions.
|
53
|
+
a = 'foo'
|
54
|
+
b = 'bar'
|
55
|
+
a + b
|
56
|
+
#=> 'foobar'
|
57
|
+
|
58
|
+
## A test will pass when its return
|
59
|
+
## value equals the expectation.
|
60
|
+
'foo'.class
|
61
|
+
#=> String
|
62
|
+
|
63
|
+
## The expectations are evaluated as well.
|
64
|
+
81
|
65
|
+
#=> 9 * 9
|
66
|
+
|
67
|
+
## Here's an example of testing errors
|
68
|
+
begin
|
69
|
+
raise RuntimeError
|
70
|
+
rescue RuntimeError
|
71
|
+
:success
|
72
|
+
end
|
73
|
+
#=> :success
|
74
|
+
```
|
75
|
+
|
76
|
+
For real world examples, see [Onetimesecret](https://github.com/onetimesecret/onetimesecret/) tryouts.
|
77
|
+
|
78
|
+
|
79
|
+
### Test setup / cleanup
|
80
|
+
|
81
|
+
Put the setup code at the top of the file, and cleanup code at the bottom. Like this:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
# This is called before all tests
|
85
|
+
require 'gibbler'
|
86
|
+
Gibbler.digest_type = Digest::SHA256
|
87
|
+
|
88
|
+
|
89
|
+
## This is a single testcase
|
90
|
+
:anything.gibbler
|
91
|
+
#=> '8574309'
|
92
|
+
|
93
|
+
|
94
|
+
# This will be called after all tests
|
95
|
+
Gibbler.digest_type = Digest::SHA1
|
96
|
+
```
|
97
|
+
|
98
|
+
__
|
99
|
+
|
100
|
+
|
101
|
+
## Thanks
|
102
|
+
|
103
|
+
* [cloudhead](https://github.com/cloudhead)
|
104
|
+
* [mynyml](https://github.com/mynyml)
|
105
|
+
* [Syntenic](https://syntenic.com/) for the hackfest venue.
|
106
|
+
* [AlexPeuchert](https://www.rubypulse.com/) for the screencast.
|
107
|
+
* Christian Michon for suggesting a better default output format.
|
108
|
+
|
109
|
+
*This collision was brought to you by Montreal.rb.*
|
data/exe/try
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require_relative '../lib/tryouts'
|
5
|
+
|
6
|
+
# Add local lib directories to the load path
|
7
|
+
Dir.glob(File.join(Dir.pwd, '{lib,..,lib}')).each { |dir| $LOAD_PATH.unshift(dir) }
|
8
|
+
|
9
|
+
# Parse command-line arguments
|
10
|
+
options = { quiet: false, noisy: false, fails: false }
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.on('-V', '--version', 'Display the version') { puts "Tryouts: #{Tryouts::VERSION}"; exit }
|
13
|
+
opts.on('-q', '--quiet', 'Run in quiet mode') { options[:quiet] = true }
|
14
|
+
opts.on('-v', '--verbose', 'Run in verbose mode') { options[:noisy] = true }
|
15
|
+
opts.on('-f', '--fails', 'Show only failing tryouts') { options[:fails] = true }
|
16
|
+
opts.on('-D', '--debug', 'Run in debug mode') { Tryouts.debug = true }
|
17
|
+
opts.on('-h', '--help', 'Display this help') { puts opts; exit }
|
18
|
+
end.parse!
|
19
|
+
|
20
|
+
# Set Tryouts options
|
21
|
+
Tryouts.quiet = options[:quiet]
|
22
|
+
Tryouts.noisy = options[:noisy]
|
23
|
+
Tryouts.fails = options[:fails]
|
24
|
+
|
25
|
+
# Find tryouts path
|
26
|
+
if ARGV.empty?
|
27
|
+
paths = Dir.glob(
|
28
|
+
['./{try,tryouts/,.}/*_{try,tryouts}.rb'],
|
29
|
+
base: Dir.pwd,
|
30
|
+
sort: true # deterministic order
|
31
|
+
)
|
32
|
+
|
33
|
+
else
|
34
|
+
paths = ARGV
|
35
|
+
end
|
36
|
+
|
37
|
+
exit Tryouts.run_all(*paths)
|
data/exe/tryouts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class Tryouts
|
2
|
+
module VERSION
|
3
|
+
def self.to_s
|
4
|
+
load_config
|
5
|
+
[@version[:MAJOR], @version[:MINOR], @version[:PATCH]].join('.')
|
6
|
+
end
|
7
|
+
alias_method :inspect, :to_s
|
8
|
+
def self.load_config
|
9
|
+
require 'yaml'
|
10
|
+
@version ||= YAML.load_file(File.join(TRYOUTS_LIB_HOME, '..', 'VERSION.yml'))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/tryouts.rb
CHANGED
@@ -1,84 +1,76 @@
|
|
1
|
-
#require 'pathname'
|
2
|
-
#p Pathname(caller.last.split(':').first)
|
3
1
|
require 'ostruct'
|
4
2
|
|
5
3
|
unless defined?(TRYOUTS_LIB_HOME)
|
6
|
-
TRYOUTS_LIB_HOME = File.expand_path File.dirname(__FILE__)
|
7
|
-
end
|
8
|
-
|
9
|
-
class Tryouts
|
10
|
-
module VERSION
|
11
|
-
def self.to_s
|
12
|
-
load_config
|
13
|
-
[@version[:MAJOR], @version[:MINOR], @version[:PATCH]].join('.')
|
14
|
-
end
|
15
|
-
alias_method :inspect, :to_s
|
16
|
-
def self.load_config
|
17
|
-
require 'yaml'
|
18
|
-
@version ||= YAML.load_file(File.join(TRYOUTS_LIB_HOME, '..', 'VERSION.yml'))
|
19
|
-
end
|
20
|
-
end
|
4
|
+
TRYOUTS_LIB_HOME = File.expand_path File.dirname(__FILE__)
|
21
5
|
end
|
22
6
|
|
7
|
+
require_relative 'tryouts/version'
|
23
8
|
|
24
9
|
class Tryouts
|
25
10
|
@debug = false
|
26
11
|
@quiet = false
|
27
12
|
@noisy = false
|
13
|
+
@fails = false
|
28
14
|
@container = Class.new
|
29
15
|
@cases = []
|
30
16
|
@sysinfo = nil
|
31
17
|
class << self
|
32
|
-
attr_accessor :debug, :container, :quiet, :noisy
|
18
|
+
attr_accessor :debug, :container, :quiet, :noisy, :fails
|
33
19
|
attr_reader :cases
|
34
|
-
|
20
|
+
|
35
21
|
def sysinfo
|
36
22
|
require 'sysinfo'
|
37
23
|
@sysinfo ||= SysInfo.new
|
38
24
|
@sysinfo
|
39
25
|
end
|
40
|
-
|
26
|
+
|
41
27
|
def debug?() @debug == true end
|
42
|
-
|
28
|
+
|
43
29
|
def run_all *paths
|
44
30
|
batches = paths.collect do |path|
|
45
31
|
parse path
|
46
32
|
end
|
47
|
-
|
33
|
+
|
48
34
|
all, skipped_tests, failed_tests = 0, 0, 0
|
49
35
|
skipped_batches, failed_batches = 0, 0
|
50
|
-
|
36
|
+
|
51
37
|
msg 'Ruby %s @ %-40s' % [RUBY_VERSION, Time.now], $/
|
52
|
-
|
38
|
+
|
39
|
+
if Tryouts.debug?
|
40
|
+
Tryouts.debug "Found #{paths.size} files:"
|
41
|
+
paths.each { |path| Tryouts.debug " #{path}" }
|
42
|
+
Tryouts.debug
|
43
|
+
end
|
44
|
+
|
53
45
|
batches.each do |batch|
|
54
|
-
|
46
|
+
|
55
47
|
path = batch.path.gsub(/#{Dir.pwd}\/?/, '')
|
56
|
-
|
48
|
+
|
57
49
|
vmsg '%-60s %s' % [path, '']
|
58
|
-
|
50
|
+
|
59
51
|
before_handler = Proc.new do |t|
|
60
|
-
if Tryouts.noisy
|
61
|
-
vmsg Console.reverse(' %-58s ' % [t.desc.to_s])
|
52
|
+
if Tryouts.noisy && !Tryouts.fails
|
53
|
+
vmsg Console.reverse(' %-58s ' % [t.desc.to_s])
|
62
54
|
vmsg t.test.inspect, t.exps.inspect
|
63
55
|
end
|
64
56
|
end
|
65
|
-
|
57
|
+
|
66
58
|
batch.run(before_handler) do |t|
|
67
|
-
if t.failed?
|
59
|
+
if t.failed?
|
68
60
|
failed_tests += 1
|
69
|
-
if Tryouts.noisy
|
61
|
+
if Tryouts.noisy && Tryouts.fails
|
70
62
|
vmsg Console.color(:red, t.failed.join($/)), $/
|
71
63
|
else
|
72
64
|
msg ' %s (%s:%s)' % [Console.color(:red, "FAIL"), path, t.exps.first]
|
73
65
|
end
|
74
|
-
elsif t.skipped? || !t.run?
|
66
|
+
elsif (t.skipped? || !t.run?) && !Tryouts.fails
|
75
67
|
skipped_tests += 1
|
76
68
|
if Tryouts.noisy
|
77
69
|
vmsg Console.bright(t.skipped.join($/)), $/
|
78
70
|
else
|
79
71
|
msg ' SKIP (%s:%s)' % [path, t.exps.first]
|
80
72
|
end
|
81
|
-
|
73
|
+
elsif !Tryouts.fails
|
82
74
|
if Tryouts.noisy
|
83
75
|
vmsg Console.color(:green, t.passed.join($/)), $/
|
84
76
|
else
|
@@ -88,7 +80,7 @@ class Tryouts
|
|
88
80
|
all += 1
|
89
81
|
end
|
90
82
|
end
|
91
|
-
|
83
|
+
|
92
84
|
msg
|
93
85
|
if all > 0
|
94
86
|
suffix = 'tests passed'
|
@@ -100,22 +92,22 @@ class Tryouts
|
|
100
92
|
suffix = "batches passed"
|
101
93
|
suffix << " (and #{skipped_batches} skipped)" if skipped_batches > 0
|
102
94
|
msg cformat(batches.size-skipped_batches-failed_batches, batches.size-skipped_batches, suffix)
|
103
|
-
end
|
95
|
+
end
|
104
96
|
end
|
105
|
-
|
97
|
+
|
106
98
|
failed_tests # 0 means success
|
107
99
|
end
|
108
|
-
|
100
|
+
|
109
101
|
def cformat(*args)
|
110
102
|
Console.bright '%d of %d %s' % args
|
111
103
|
end
|
112
|
-
|
104
|
+
|
113
105
|
def run path
|
114
106
|
batch = parse path
|
115
107
|
batch.run
|
116
108
|
batch
|
117
109
|
end
|
118
|
-
|
110
|
+
|
119
111
|
def parse path
|
120
112
|
#debug "Loading #{path}"
|
121
113
|
lines = File.readlines path
|
@@ -139,17 +131,17 @@ class Tryouts
|
|
139
131
|
end
|
140
132
|
exps.last += 1
|
141
133
|
end
|
142
|
-
|
134
|
+
|
143
135
|
offset = 0
|
144
136
|
buffer, desc = Section.new(path), Section.new(path)
|
145
|
-
test = Section.new(path, idx) # test start the line before the exp.
|
137
|
+
test = Section.new(path, idx) # test start the line before the exp.
|
146
138
|
blank_buffer = Section.new(path)
|
147
139
|
while (idx-offset >= 0)
|
148
140
|
offset += 1
|
149
141
|
this_line = lines[idx-offset].chomp
|
150
142
|
buffer.unshift this_line if ignore?(this_line)
|
151
143
|
if comment?(this_line)
|
152
|
-
buffer.unshift this_line
|
144
|
+
buffer.unshift this_line
|
153
145
|
end
|
154
146
|
if test?(this_line)
|
155
147
|
test.unshift(*buffer) && buffer.clear
|
@@ -167,47 +159,47 @@ class Tryouts
|
|
167
159
|
desc.unshift *buffer
|
168
160
|
desc.last = test.first-1
|
169
161
|
desc.first = desc.last-desc.size+1
|
170
|
-
# remove empty lines between the description
|
162
|
+
# remove empty lines between the description
|
171
163
|
# and the previous expectation
|
172
|
-
while !desc.empty? && desc[0].empty?
|
164
|
+
while !desc.empty? && desc[0].empty?
|
173
165
|
desc.shift
|
174
166
|
desc.first += 1
|
175
167
|
end
|
176
|
-
break
|
168
|
+
break
|
177
169
|
end
|
178
170
|
end
|
179
|
-
|
171
|
+
|
180
172
|
batch << TestCase.new(desc, test, exps)
|
181
173
|
end
|
182
174
|
end
|
183
|
-
|
175
|
+
|
184
176
|
batch
|
185
177
|
end
|
186
|
-
|
178
|
+
|
187
179
|
def print str
|
188
180
|
return if Tryouts.quiet
|
189
181
|
STDOUT.print str
|
190
182
|
STDOUT.flush
|
191
183
|
end
|
192
|
-
|
184
|
+
|
193
185
|
def vmsg *msg
|
194
186
|
STDOUT.puts *msg if !Tryouts.quiet && Tryouts.noisy
|
195
187
|
end
|
196
|
-
|
188
|
+
|
197
189
|
def msg *msg
|
198
190
|
STDOUT.puts *msg unless Tryouts.quiet
|
199
191
|
end
|
200
|
-
|
192
|
+
|
201
193
|
def err *msg
|
202
194
|
msg.each do |line|
|
203
195
|
STDERR.puts Console.color :red, line
|
204
196
|
end
|
205
197
|
end
|
206
|
-
|
198
|
+
|
207
199
|
def debug *msg
|
208
200
|
STDERR.puts *msg if @debug
|
209
201
|
end
|
210
|
-
|
202
|
+
|
211
203
|
def eval(str, path, line)
|
212
204
|
begin
|
213
205
|
Kernel.eval str, @container.send(:binding), path, line
|
@@ -217,34 +209,34 @@ class Tryouts
|
|
217
209
|
nil
|
218
210
|
end
|
219
211
|
end
|
220
|
-
|
212
|
+
|
221
213
|
private
|
222
|
-
|
214
|
+
|
223
215
|
def expectation? str
|
224
216
|
!ignore?(str) && str.strip.match(/\A\#+\s*=>/)
|
225
217
|
end
|
226
|
-
|
218
|
+
|
227
219
|
def comment? str
|
228
220
|
!str.strip.match(/^\#+/).nil? && !expectation?(str)
|
229
221
|
end
|
230
|
-
|
222
|
+
|
231
223
|
def test? str
|
232
224
|
!ignore?(str) && !expectation?(str) && !comment?(str)
|
233
225
|
end
|
234
|
-
|
226
|
+
|
235
227
|
def ignore? str
|
236
228
|
str.to_s.strip.chomp.empty?
|
237
229
|
end
|
238
|
-
|
230
|
+
|
239
231
|
def test_begin? str
|
240
232
|
ret = !str.strip.match(/\#+\s*TEST/i).nil? ||
|
241
233
|
!str.strip.match(/\A\#\#+[\s\w]+/i).nil?
|
242
234
|
ret
|
243
235
|
end
|
244
236
|
|
245
|
-
|
237
|
+
|
246
238
|
end
|
247
|
-
|
239
|
+
|
248
240
|
class TestBatch < Array
|
249
241
|
class Container
|
250
242
|
def metaclass
|
@@ -262,12 +254,12 @@ class Tryouts
|
|
262
254
|
def run(before_test, &after_test)
|
263
255
|
return if empty?
|
264
256
|
setup
|
265
|
-
ret = self.select { |tc|
|
257
|
+
ret = self.select { |tc|
|
266
258
|
before_test.call(tc) unless before_test.nil?
|
267
|
-
ret = !tc.run
|
259
|
+
ret = !tc.run
|
268
260
|
after_test.call(tc)
|
269
261
|
ret # select failed tests
|
270
|
-
}
|
262
|
+
}
|
271
263
|
@failed = ret.size
|
272
264
|
@run = true
|
273
265
|
clean
|
@@ -306,27 +298,27 @@ class Tryouts
|
|
306
298
|
def run
|
307
299
|
Tryouts.debug '%s:%d' % [@test.path, @test.first]
|
308
300
|
Tryouts.debug inspect, $/
|
309
|
-
expectations = exps.collect { |exp,idx|
|
301
|
+
expectations = exps.collect { |exp,idx|
|
310
302
|
exp =~ /\A\#?\s*=>\s*(.+)\Z/
|
311
303
|
$1 # this will be nil if the expectation is commented out
|
312
304
|
}
|
313
|
-
|
305
|
+
|
314
306
|
# Evaluate test block only if there are valid expectations
|
315
307
|
unless expectations.compact.empty?
|
316
308
|
test_value = Tryouts.eval @test.to_s, @test.path, @test.first
|
317
309
|
@has_run = true
|
318
310
|
end
|
319
|
-
|
311
|
+
|
320
312
|
@passed, @failed, @skipped = [], [], []
|
321
|
-
expectations.each_with_index { |exp,idx|
|
313
|
+
expectations.each_with_index { |exp,idx|
|
322
314
|
if exp.nil?
|
323
315
|
@skipped << ' [skipped]'
|
324
316
|
else
|
325
317
|
exp_value = Tryouts.eval(exp, @exps.path, @exps.first+idx)
|
326
318
|
if test_value == exp_value
|
327
|
-
@passed << ' == %s' % [test_value.inspect]
|
319
|
+
@passed << ' == %s' % [test_value.inspect]
|
328
320
|
else
|
329
|
-
@failed << ' != %s' % [test_value.inspect]
|
321
|
+
@failed << ' != %s' % [test_value.inspect]
|
330
322
|
end
|
331
323
|
end
|
332
324
|
}
|
@@ -366,9 +358,9 @@ class Tryouts
|
|
366
358
|
end
|
367
359
|
end
|
368
360
|
|
369
|
-
|
361
|
+
|
370
362
|
module Console
|
371
|
-
|
363
|
+
|
372
364
|
# ANSI escape sequence numbers for text attributes
|
373
365
|
ATTRIBUTES = {
|
374
366
|
:normal => 0,
|
@@ -408,7 +400,7 @@ class Tryouts
|
|
408
400
|
:default => 49,
|
409
401
|
:random => 40 + rand(10).to_i
|
410
402
|
}.freeze unless defined? BGCOLOURS
|
411
|
-
|
403
|
+
|
412
404
|
module InstanceMethods
|
413
405
|
def bright
|
414
406
|
Console.bright(self)
|
@@ -426,7 +418,7 @@ class Tryouts
|
|
426
418
|
Console.bgcolor(col, self)
|
427
419
|
end
|
428
420
|
end
|
429
|
-
|
421
|
+
|
430
422
|
def self.bright(str)
|
431
423
|
str = [style(ATTRIBUTES[:bright]), str, default_style].join
|
432
424
|
str.extend Console::InstanceMethods
|
@@ -463,4 +455,3 @@ class Tryouts
|
|
463
455
|
end
|
464
456
|
|
465
457
|
end
|
466
|
-
|
metadata
CHANGED
@@ -1,42 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tryouts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delano Mandelbaum
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.9.0.pre.RC1
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.9.0.pre.RC1
|
27
|
-
description: Don't waste your time writing tests
|
28
|
-
email: delano@solutious.com
|
11
|
+
date: 2024-06-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple test framework for Ruby code that uses introspection to allow
|
14
|
+
defining checks in comments.
|
15
|
+
email: gems@solutious.com
|
29
16
|
executables:
|
30
17
|
- try
|
18
|
+
- tryouts
|
31
19
|
extensions: []
|
32
20
|
extra_rdoc_files: []
|
33
21
|
files:
|
34
22
|
- LICENSE.txt
|
35
|
-
- README.
|
36
|
-
-
|
37
|
-
-
|
23
|
+
- README.md
|
24
|
+
- exe/try
|
25
|
+
- exe/tryouts
|
38
26
|
- lib/tryouts.rb
|
39
|
-
|
27
|
+
- lib/tryouts/version.rb
|
28
|
+
homepage: https://github.com/delano/tryouts
|
40
29
|
licenses:
|
41
30
|
- MIT
|
42
31
|
metadata: {}
|
@@ -48,15 +37,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
37
|
requirements:
|
49
38
|
- - ">="
|
50
39
|
- !ruby/object:Gem::Version
|
51
|
-
version:
|
40
|
+
version: 2.7.8
|
52
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
42
|
requirements:
|
54
|
-
- - "
|
43
|
+
- - ">="
|
55
44
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
45
|
+
version: '0'
|
57
46
|
requirements: []
|
58
|
-
rubygems_version: 3.
|
47
|
+
rubygems_version: 3.5.7
|
59
48
|
signing_key:
|
60
49
|
specification_version: 4
|
61
|
-
summary:
|
50
|
+
summary: Ruby tests that read like documentation.
|
62
51
|
test_files: []
|
data/README.rdoc
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
= Tryouts v2.0 ALPHA
|
2
|
-
|
3
|
-
<i>Don't waste your time writing tests.</i>
|
4
|
-
|
5
|
-
<b>NOTE: Tryouts syntax changed since 0.x. The old version is still available in the 0.8-FINAL branch.</b>
|
6
|
-
|
7
|
-
Check out the screencast[http://www.rubypulse.com/episode-0.46_tryouts.html] created by Alex Peuchert.
|
8
|
-
|
9
|
-
|
10
|
-
== Basic syntax
|
11
|
-
|
12
|
-
## A very simple test
|
13
|
-
1 + 1
|
14
|
-
#=> 2
|
15
|
-
|
16
|
-
## The test description can spread
|
17
|
-
## across multiple lines. The same
|
18
|
-
## is true for test definitions.
|
19
|
-
a = 'foo'
|
20
|
-
b = 'bar'
|
21
|
-
a + b
|
22
|
-
#=> 'foobar'
|
23
|
-
|
24
|
-
## A test will pass when its return
|
25
|
-
## value equals the expectation.
|
26
|
-
'foo'.class
|
27
|
-
#=> String
|
28
|
-
|
29
|
-
## The expectations are evaluated.
|
30
|
-
1 + 1
|
31
|
-
#=> 1 + 1
|
32
|
-
|
33
|
-
## Here's an example of testing errors
|
34
|
-
begin
|
35
|
-
raise RuntimeError
|
36
|
-
rescue RuntimeError
|
37
|
-
:success
|
38
|
-
end
|
39
|
-
#=> :success
|
40
|
-
|
41
|
-
For real world examples, see the Gibbler[http://github.com/delano/gibbler/tree/master/try/] tryouts.
|
42
|
-
|
43
|
-
== Setup / Cleanup
|
44
|
-
|
45
|
-
All code before the first test definition is assumed to be setup code. All code after the last definition is assumed to be cleanup code. Here is an example:
|
46
|
-
|
47
|
-
|
48
|
-
# This is called before all tests
|
49
|
-
require 'gibbler'
|
50
|
-
Gibbler.digest_type = Digest::SHA256
|
51
|
-
|
52
|
-
## A Symbol can gibbler
|
53
|
-
:anything.gibbler
|
54
|
-
#=> '754f87ca720ec256633a286d9270d68478850b2abd7b0ae65021cb769ae70c08'
|
55
|
-
|
56
|
-
# This will be called after all tests
|
57
|
-
Gibbler.digest_type = Digest::SHA1
|
58
|
-
|
59
|
-
|
60
|
-
== Running Tests
|
61
|
-
|
62
|
-
Try ships with a command-line tool called <tt>try</tt>. When called with no arguments, it will look for files ending with _try.rb in the current directory, or in the subfolder try.
|
63
|
-
|
64
|
-
You can also supply a specific file to test.
|
65
|
-
|
66
|
-
$ try path/2/test.rb
|
67
|
-
Ruby 1.9.1 @ 2011-01-06 12:38:29 -0500
|
68
|
-
|
69
|
-
# TEST 1: test matches result with expectation
|
70
|
-
7 a = 1 + 1
|
71
|
-
8 #=> 2
|
72
|
-
== 2
|
73
|
-
...
|
74
|
-
|
75
|
-
## TEST 12: comments, tests, and expectations can
|
76
|
-
## contain multiple lines
|
77
|
-
13 a = 1
|
78
|
-
14 b = 2
|
79
|
-
15 a + b
|
80
|
-
16 # => 3
|
81
|
-
17 # => 2 + 1
|
82
|
-
== 3
|
83
|
-
== 3
|
84
|
-
|
85
|
-
12 of 12 tests passed (and 5 skipped)
|
86
|
-
|
87
|
-
|
88
|
-
If all tests pass, try exits with a 0. Otherwise it exits with the number of tests that failed.
|
89
|
-
|
90
|
-
|
91
|
-
For reduced output, use the `-q` option:
|
92
|
-
|
93
|
-
$ try -q
|
94
|
-
Ruby 1.9.1 @ 2011-01-06 12:38:29 -0500
|
95
|
-
|
96
|
-
42 of 42 tests passed (and 5 skipped)
|
97
|
-
4 of 4 batches passed
|
98
|
-
|
99
|
-
|
100
|
-
== Installation
|
101
|
-
|
102
|
-
One of:
|
103
|
-
|
104
|
-
$ gem install tryouts
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
== Credits
|
109
|
-
|
110
|
-
* delano[http://github.com/delano]
|
111
|
-
|
112
|
-
With help from:
|
113
|
-
|
114
|
-
* cloudhead[http://github.com/cloudhead]
|
115
|
-
* mynyml[http://github.com/mynyml]
|
116
|
-
|
117
|
-
== Thanks
|
118
|
-
|
119
|
-
* Syntenic[http://syntenic.com/] for the hackfest venue.
|
120
|
-
* AlexPeuchert[http://www.rubypulse.com/] for the screencast.
|
121
|
-
* Christian Michon for suggesting a better default output format.
|
122
|
-
|
123
|
-
<i>This collision was brought to you by Montreal.rb.</i>
|
data/Rakefile
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "rake"
|
3
|
-
require "rake/clean"
|
4
|
-
require 'yaml'
|
5
|
-
|
6
|
-
begin
|
7
|
-
require 'hanna/rdoctask'
|
8
|
-
rescue LoadError
|
9
|
-
require 'rake/rdoctask'
|
10
|
-
end
|
11
|
-
|
12
|
-
config = YAML.load_file("VERSION.yml")
|
13
|
-
task :default => ["build"]
|
14
|
-
CLEAN.include [ 'pkg', 'doc' ]
|
15
|
-
name = "stella"
|
16
|
-
|
17
|
-
begin
|
18
|
-
require "jeweler"
|
19
|
-
Jeweler::Tasks.new do |gem|
|
20
|
-
gem.version = "#{config[:MAJOR]}.#{config[:MINOR]}.#{config[:PATCH]}"
|
21
|
-
gem.name = "tryouts"
|
22
|
-
gem.rubyforge_project = gem.name
|
23
|
-
gem.summary = "Don't waste your time writing tests"
|
24
|
-
gem.description = gem.summary
|
25
|
-
gem.email = "delano@solutious.com"
|
26
|
-
gem.homepage = "http://github.com/delano/tryouts"
|
27
|
-
gem.authors = ["Delano Mandelbaum"]
|
28
|
-
gem.add_dependency("sysinfo", ">= 0.7.3")
|
29
|
-
end
|
30
|
-
Jeweler::GemcutterTasks.new
|
31
|
-
rescue LoadError
|
32
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
Rake::RDocTask.new do |rdoc|
|
37
|
-
version = "#{config[:MAJOR]}.#{config[:MINOR]}.#{config[:PATCH]}}"
|
38
|
-
rdoc.rdoc_dir = "doc"
|
39
|
-
rdoc.title = "stella #{version}"
|
40
|
-
rdoc.rdoc_files.include("README*")
|
41
|
-
rdoc.rdoc_files.include("LICENSE.txt")
|
42
|
-
rdoc.rdoc_files.include("bin/*.rb")
|
43
|
-
rdoc.rdoc_files.include("lib/**/*.rb")
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
# Rubyforge Release / Publish Tasks ==================================
|
48
|
-
|
49
|
-
#about 'Publish website to rubyforge'
|
50
|
-
task 'publish:rdoc' => 'doc/index.html' do
|
51
|
-
sh "scp -rp doc/* rubyforge.org:/var/www/gforge-projects/#{name}/"
|
52
|
-
end
|
53
|
-
|
54
|
-
#about 'Public release to rubyforge'
|
55
|
-
task 'publish:gem' => [:package] do |t|
|
56
|
-
sh <<-end
|
57
|
-
rubyforge add_release -o Any -a CHANGES.txt -f -n README.md #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.gem &&
|
58
|
-
rubyforge add_file -o Any -a CHANGES.txt -f -n README.md #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.tgz
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
|
data/bin/try
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
#
|
4
|
-
# Tryouts - Don't waste your time writing tests
|
5
|
-
#
|
6
|
-
# Usage:
|
7
|
-
#
|
8
|
-
# $ try
|
9
|
-
# $ try -q
|
10
|
-
# $ try -v
|
11
|
-
# $ try path/2/file.rb
|
12
|
-
# $ try -q path/2/file.rb path/2/another.rb
|
13
|
-
#
|
14
|
-
|
15
|
-
# Put our local lib in first place
|
16
|
-
BASE_PATH = File.expand_path File.join(File.dirname(__FILE__), '..')
|
17
|
-
lib_dir = File.join(BASE_PATH, 'lib')
|
18
|
-
$:.unshift lib_dir
|
19
|
-
|
20
|
-
require 'tryouts'
|
21
|
-
|
22
|
-
# Help out the requires in the tryouts
|
23
|
-
[File.join(Dir.pwd, 'lib'), File.join(Dir.pwd, '..', 'lib')].each do |dir|
|
24
|
-
$:.unshift dir
|
25
|
-
end
|
26
|
-
|
27
|
-
unless ARGV.delete('-V').nil?
|
28
|
-
puts "Tryouts: #{Tryouts::VERSION}"
|
29
|
-
exit
|
30
|
-
end
|
31
|
-
|
32
|
-
Tryouts.quiet = !ARGV.delete('-q').nil? # eg try -q [PATH]
|
33
|
-
Tryouts.noisy = !ARGV.delete('-v').nil? # eg try -v [PATH]
|
34
|
-
|
35
|
-
if ARGV.empty?
|
36
|
-
paths = Dir.glob(File.join(Dir.pwd, '{try,tryouts}', '*_{try,tryouts}.rb'))
|
37
|
-
paths += Dir.glob(File.join(Dir.pwd, '*_{try,tryouts}.rb'))
|
38
|
-
else
|
39
|
-
paths = ARGV
|
40
|
-
end
|
41
|
-
|
42
|
-
#Tryouts.quiet
|
43
|
-
#Tryouts.debug = true
|
44
|
-
#Tryouts.container = self
|
45
|
-
|
46
|
-
exit Tryouts.run_all(*paths)
|
47
|
-
|