tryouts 0.8.8 → 2.0.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.
- data/.gitignore +1 -0
- data/LICENSE.txt +1 -1
- data/README.rdoc +64 -228
- data/Rakefile +42 -65
- data/VERSION.yml +5 -0
- data/bin/try +26 -0
- data/lib/sysinfo.rb +278 -0
- data/lib/tryouts.rb +405 -320
- data/try/step1_try.rb +51 -0
- data/try/step2_try.rb +59 -0
- data/try/step3_try.rb +19 -0
- data/try/step4_try.rb +6 -0
- metadata +20 -75
- data/CHANGES.txt +0 -202
- data/bin/mockout +0 -54
- data/bin/sergeant +0 -66
- data/lib/tryouts/cli/run.rb +0 -229
- data/lib/tryouts/cli.rb +0 -15
- data/lib/tryouts/drill/context.rb +0 -33
- data/lib/tryouts/drill/dream.rb +0 -57
- data/lib/tryouts/drill/reality.rb +0 -49
- data/lib/tryouts/drill/response.rb +0 -117
- data/lib/tryouts/drill/sergeant/api.rb +0 -42
- data/lib/tryouts/drill/sergeant/benchmark.rb +0 -76
- data/lib/tryouts/drill/sergeant/cli.rb +0 -66
- data/lib/tryouts/drill/sergeant/rbenchmark.rb +0 -132
- data/lib/tryouts/drill.rb +0 -224
- data/lib/tryouts/mixins.rb +0 -37
- data/lib/tryouts/orderedhash.rb +0 -199
- data/lib/tryouts/stats.rb +0 -96
- data/lib/tryouts/tryout.rb +0 -176
- data/tryouts/01_mixins_tryouts.rb +0 -23
- data/tryouts/10_syntax_tryouts.rb +0 -44
- data/tryouts/14_set_tryouts.rb +0 -26
- data/tryouts/15_dreams_tryouts.rb +0 -54
- data/tryouts/20_cli_tryouts.rb +0 -40
- data/tryouts/30_benchmark_tryouts.rb +0 -27
- data/tryouts/50_class_context_tryouts.rb +0 -33
- data/tryouts/X1_new_api_syntax.rb +0 -78
- data/tryouts/X2_new_cli_syntax.rb +0 -36
- data/tryouts/standalone_test.rb +0 -39
- data/tryouts.gemspec +0 -84
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gemspec
|
data/LICENSE.txt
CHANGED
data/README.rdoc
CHANGED
@@ -1,257 +1,93 @@
|
|
1
|
-
= Tryouts
|
1
|
+
= Tryouts v2.0 ALPHA
|
2
2
|
|
3
|
-
|
3
|
+
<i>Put your Ruby tests in comments.</i>
|
4
4
|
|
5
|
-
|
5
|
+
<b>NOTE: Tryouts syntax changed 0.x. The old version is still available in the 0.8-FINAL branch.</b>
|
6
6
|
|
7
|
-
=== Terminology
|
8
7
|
|
9
|
-
|
10
|
-
* Drill: a single test.
|
11
|
-
* Drill Sergeant: The class responsible for executing a drill.
|
12
|
-
* Dream: the expected outcome of a drill. There's always one or more dream per drill.
|
13
|
-
|
14
|
-
== Installation
|
15
|
-
|
16
|
-
Via Rubygems, one of:
|
17
|
-
|
18
|
-
$ gem install tryouts
|
19
|
-
$ gem install delano-tryouts
|
20
|
-
|
21
|
-
or via download:
|
22
|
-
* tryouts-latest.tar.gz[http://github.com/delano/tryouts/tarball/latest]
|
23
|
-
* tryouts-latest.zip[http://github.com/delano/tryouts/zipball/latest]
|
24
|
-
|
25
|
-
|
26
|
-
== Writing Tests
|
27
|
-
|
28
|
-
The examples below are a complete overview of Tryouts syntax.
|
29
|
-
|
30
|
-
=== Testing Ruby Codes (:api)
|
31
|
-
|
32
|
-
library :gibbler, "../path/to/gibbler/lib"
|
33
|
-
|
34
|
-
tryouts "Common Usage", :api do
|
35
|
-
|
36
|
-
# Define variables available only within
|
37
|
-
# in the current tryout definition.
|
38
|
-
set :local_variable, 3
|
39
|
-
|
40
|
-
setup do
|
41
|
-
# do stuff before all drills
|
42
|
-
end
|
43
|
-
|
44
|
-
clean do
|
45
|
-
# do stuff after all drills
|
46
|
-
end
|
47
|
-
|
48
|
-
# This drill block should return 3.
|
49
|
-
drill "Maths R Us", local_variable do
|
50
|
-
12 / 4
|
51
|
-
end
|
52
|
-
|
53
|
-
# You can specify a method to execute
|
54
|
-
# on the return value of the drill block.
|
55
|
-
drill "We want a symbol", :class, Symbol do
|
56
|
-
Class.methods.first
|
57
|
-
end
|
58
|
-
|
59
|
-
# Dreams can also be specified explicitly which is
|
60
|
-
# important b/c it's possible to specify multiple.
|
61
|
-
dream :class, Array
|
62
|
-
dream ['b', 'c', 'd']
|
63
|
-
drill "Should return a list of 3" do
|
64
|
-
letters = 'a'..'z'
|
65
|
-
letters.to_a[1..local_variable]
|
66
|
-
end
|
67
|
-
|
68
|
-
# Drills can pass based on an exception too.
|
69
|
-
dream :exception, NameError
|
70
|
-
drill "Something failed" do
|
71
|
-
raise NameError
|
72
|
-
end
|
73
|
-
|
74
|
-
# We can even put simple drills on a single line.
|
75
|
-
drill 'Small, fast, and furious', 'Muggsy Bogues', :match, /Mug+sy Bogu?es/
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
=== Testing Command-Line Applications (:cli)
|
81
|
-
|
82
|
-
You can execute drills on command-line applications.
|
8
|
+
== Basic syntax
|
83
9
|
|
84
|
-
|
10
|
+
## A very simple test
|
11
|
+
1 + 1
|
12
|
+
#=> 2
|
13
|
+
|
14
|
+
## The test description can spread
|
15
|
+
## across multiple lines. The same
|
16
|
+
## is true for test definitions.
|
17
|
+
a = 'foo'
|
18
|
+
b = 'bar'
|
19
|
+
a + b
|
20
|
+
#=> 'foobar'
|
21
|
+
|
22
|
+
## A test will pass when its return
|
23
|
+
## value equals the expectation.
|
24
|
+
'foo'.class
|
25
|
+
#=> String
|
26
|
+
|
27
|
+
## The expectations are evaluated.
|
28
|
+
1 + 1
|
29
|
+
#=> 1 + 1
|
85
30
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
drill "can display my IP addresses", :myaddress, :e
|
92
|
-
|
93
|
-
# The drill returns an Array of lines from STDOUT so
|
94
|
-
# we can use Array#grep to check the command output.
|
95
|
-
# If any lines match, this test will pass.
|
96
|
-
dream :grep, /No machines running/
|
97
|
-
drill "can call with no arguments"
|
98
|
-
|
99
|
-
# Drills can also be defined with a block which gets
|
100
|
-
# executed via Rye::Box#batch. Methods in the block
|
101
|
-
# are executed as commands. The return value of the
|
102
|
-
# block is considered the test output.
|
103
|
-
dream :match, /\d+\.\d+\.\d+\.\d+/
|
104
|
-
drill "can execute a block of commands" do
|
105
|
-
ret = rudy :q, :myaddress, :e
|
106
|
-
ret.first
|
31
|
+
## Here's an example of testing errors
|
32
|
+
begin
|
33
|
+
raise RuntimeError
|
34
|
+
rescue RuntimeError
|
35
|
+
:success
|
107
36
|
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
=== Running Performance Benchmarks (:benchmark)
|
112
|
-
|
113
|
-
You can also use Tryouts to run benchmarks. The tryouts method takes a second parameter which specifies which drill sergeant to use. Below we specify <tt>:benchmark</tt> so each drill is timed and executed multiple times.
|
37
|
+
#=> :success
|
114
38
|
|
115
|
-
|
116
|
-
|
117
|
-
# We create an Array and store it in a class
|
118
|
-
# variable so it's available to other drills.
|
119
|
-
drill "Create test array" do
|
120
|
-
@@array = (1..100000).map { rand }
|
121
|
-
end
|
122
|
-
|
123
|
-
dream :mean, 3.0 # The mean should be <= 3.0 seconds
|
124
|
-
dream :sdev, 0.1 # and the standard deviation <= 0.1
|
125
|
-
drill("Array sort!") { @@array.dup.sort! }
|
126
|
-
|
127
|
-
# You can also include a dream inline
|
128
|
-
drill("Array sort", :mean, 3.0) { @@array.dup.sort }
|
129
|
-
|
130
|
-
# The 3rd argument is the number of times to
|
131
|
-
# execute the drill block. The mean and sdev
|
132
|
-
# are calculate based on all iterations. The
|
133
|
-
# default is 5 and the maximum is 30.
|
134
|
-
dream :sdev, 0.1, 15
|
135
|
-
drill("Array sort") { @@array.dup.sort }
|
136
|
-
|
137
|
-
end
|
39
|
+
For real world examples, see the Gibbler[github.com/delano/gibbler/tree/master/try/] tryouts.
|
138
40
|
|
139
|
-
|
41
|
+
== Setup / Cleanup
|
140
42
|
|
141
|
-
|
142
|
-
|
143
|
-
Tryouts comes with an executable called <tt>sergeant</tt>. This is the drill sergeant that tells you what percentage of your dreams come true.
|
144
|
-
|
145
|
-
$ sergeant
|
43
|
+
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:
|
44
|
+
|
146
45
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
"Object" PASS
|
151
|
-
"Class" PASS
|
152
|
-
...
|
153
|
-
"Knows when an Hash has changed" PASS
|
154
|
-
|
155
|
-
All 9 dreams came true
|
156
|
-
|
157
|
-
|
158
|
-
The sergeant looks in the current working directory for a <tt>tryouts</tt> directory and will automatically load all files ending in <tt>_tryouts.rb</tt>.
|
159
|
-
|
160
|
-
$ ls -l tryouts/
|
161
|
-
01_mixins_tryouts.rb
|
162
|
-
10_syntax_tryouts.rb
|
163
|
-
20_cli_tryouts.rb
|
164
|
-
30_benchmark_tryouts.rb
|
165
|
-
50_class_context_tryouts.rb
|
46
|
+
# This is called after all tests
|
47
|
+
require 'gibbler'
|
48
|
+
Gibbler.digest_type = Digest::SHA256
|
166
49
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
Verbose mode gives you some extra information, including the return values from the drills. The more v's, the more information:
|
172
|
-
|
173
|
-
$ sergeant -v
|
50
|
+
## A Symbol can gibbler
|
51
|
+
:anything.gibbler
|
52
|
+
#=> '754f87ca720ec256633a286d9270d68478850b2abd7b0ae65021cb769ae70c08'
|
174
53
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
== Screenshots
|
181
|
-
|
182
|
-
=== :api Tryouts
|
183
|
-
|
184
|
-
http://delano.github.com/tryouts/screens/tryouts-0.8-api.png
|
185
|
-
|
186
|
-
<i>from gibbler[http://github.com/delano/gibbler/blob/master/tryouts/10_basic_tryouts.rb]</i>
|
187
|
-
|
188
|
-
|
189
|
-
=== :cli Tryouts (verbose)
|
190
|
-
|
191
|
-
http://delano.github.com/tryouts/screens/tryouts-0.8-cli.png
|
192
|
-
|
193
|
-
<i>from tryouts[http://github.com/delano/tryouts/blob/master/tryouts/20_cli_tryouts.rb]</i>
|
194
|
-
|
195
|
-
|
196
|
-
=== :benchmark Tryouts (verbose)
|
197
|
-
|
198
|
-
http://delano.github.com/tryouts/screens/tryouts-0.8-benchmark.png
|
199
|
-
|
200
|
-
<i>from gibbler[http://github.com/delano/gibbler/blob/master/tryouts/80_performance_tryouts.rb]</i>
|
201
|
-
|
202
|
-
== News
|
203
|
-
|
204
|
-
=== 2009-07-20: New DSL keyword "set"
|
205
|
-
|
206
|
-
The "set" keyword has been introduced in 0.8.4 for defining variables available only to the Tryout definition they were declared in. See Example 1.
|
207
|
-
|
208
|
-
=== 2009-07-01: Drills for command-line applications
|
209
|
-
|
210
|
-
Support for testing command-line applications has been re-introduced in 0.8. See example code further down in this README.
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
== BETA Notice
|
215
|
-
|
216
|
-
Tryouts is very new (est. 2009-05-19) and has not been vetted by the scrutiny of time. In particular you can expect:
|
217
|
-
|
218
|
-
* The test definition syntax may change in future releases.
|
219
|
-
* Unexpected errors.
|
220
|
-
* Bugs! I love fixing bugs so if you find one let me know.
|
221
|
-
|
222
|
-
|
223
|
-
== On Threads
|
54
|
+
# This will be called after all tests
|
55
|
+
Gibbler.digest_type = Digest::SHA1
|
56
|
+
|
57
|
+
|
58
|
+
== Running Tests
|
224
59
|
|
225
|
-
|
60
|
+
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.
|
226
61
|
|
62
|
+
http://delano.github.com/tryouts/screens/tryouts-2.0-success.png
|
63
|
+
|
64
|
+
You can also supply a specific file to test.
|
227
65
|
|
228
|
-
|
66
|
+
$ try path/2/test.rb
|
229
67
|
|
230
|
-
|
231
|
-
* Read the rdocs[http://tryouts.rubyforge.org/]
|
232
|
-
* About Solutious[http://solutious.com/about/]
|
233
|
-
* Inspiration[http://www.youtube.com/watch?v=iB9nhyosDVs]
|
68
|
+
If all tests pass, try exits with a 0. Otherwise it exits with the number of tests that failed.
|
234
69
|
|
70
|
+
http://delano.github.com/tryouts/screens/tryouts-2.0-failure.png
|
235
71
|
|
236
|
-
==
|
72
|
+
== Installation
|
237
73
|
|
238
|
-
|
239
|
-
* Sam Aaron (http://sam.aaron.name) for the early feedback.
|
240
|
-
* Kalin Harvey for the encouragement.
|
74
|
+
One of:
|
241
75
|
|
76
|
+
$ gem install tryouts
|
77
|
+
|
78
|
+
|
242
79
|
|
243
80
|
== Credits
|
244
81
|
|
245
|
-
*
|
82
|
+
* delano[http://github.com/delano]
|
246
83
|
|
84
|
+
With help from:
|
247
85
|
|
248
|
-
|
86
|
+
* cloudhead[http://github.com/cloudhead]
|
87
|
+
* mynyml[http://github.com/mynyml]
|
249
88
|
|
250
|
-
|
251
|
-
* Testy[http://github.com/ahoward/testy/tree/master]
|
252
|
-
* Expectations[http://expectations.rubyforge.org/]
|
253
|
-
* Zebra[http://github.com/giraffesoft/zebra/tree/master]
|
89
|
+
== Thanks
|
254
90
|
|
255
|
-
|
91
|
+
* Syntenic[http://syntenic.com/] for the hackfest venue.
|
256
92
|
|
257
|
-
|
93
|
+
<i>This collision was brought to you by Montreal.rb.</i>
|
data/Rakefile
CHANGED
@@ -1,85 +1,62 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require '
|
5
|
-
include FileUtils
|
1
|
+
require "rubygems"
|
2
|
+
require "rake"
|
3
|
+
require "rake/clean"
|
4
|
+
require 'yaml'
|
6
5
|
|
7
6
|
begin
|
8
7
|
require 'hanna/rdoctask'
|
9
8
|
rescue LoadError
|
10
9
|
require 'rake/rdoctask'
|
11
10
|
end
|
12
|
-
|
13
|
-
task :default => :package
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
CHANGES = "CHANGES.txt"
|
20
|
-
LICENSE = "LICENSE.txt"
|
21
|
-
|
22
|
-
# Files and directories to be deleted when you run "rake clean"
|
23
|
-
CLEAN.include [ 'pkg', '*.gem', '.config', 'doc']
|
24
|
-
|
25
|
-
# Virginia assumes your project and gemspec have the same name
|
26
|
-
name = (Dir.glob('*.gemspec') || ['tryouts']).first.split('.').first
|
27
|
-
load "#{name}.gemspec"
|
28
|
-
version = @spec.version
|
29
|
-
|
30
|
-
# That's it! The following defaults should allow you to get started
|
31
|
-
# on other things.
|
32
|
-
|
33
|
-
|
34
|
-
# TESTS/SPECS =========================================================
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
# INSTALL =============================================================
|
12
|
+
config = YAML.load_file("VERSION.yml")
|
13
|
+
task :default => ["build"]
|
14
|
+
CLEAN.include [ 'pkg', 'doc' ]
|
15
|
+
name = "stella"
|
39
16
|
|
40
|
-
|
41
|
-
|
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 = "Put your Ruby tests in comments."
|
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
|
+
end
|
29
|
+
Jeweler::GemcutterTasks.new
|
30
|
+
rescue LoadError
|
31
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
42
32
|
end
|
43
33
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
34
|
+
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
version = "#{config[:MAJOR]}.#{config[:MINOR]}.#{config[:PATCH]}.#{config[:BUILD]}"
|
37
|
+
rdoc.rdoc_dir = "doc"
|
38
|
+
rdoc.title = "stella #{version}"
|
39
|
+
rdoc.rdoc_files.include("README*")
|
40
|
+
rdoc.rdoc_files.include("LICENSE.txt")
|
41
|
+
rdoc.rdoc_files.include("bin/*.rb")
|
42
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
50
43
|
end
|
51
44
|
|
52
45
|
|
53
|
-
#
|
46
|
+
# Rubyforge Release / Publish Tasks ==================================
|
54
47
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
48
|
+
#about 'Publish website to rubyforge'
|
49
|
+
task 'publish:rdoc' => 'doc/index.html' do
|
50
|
+
sh "scp -rp doc/* rubyforge.org:/var/www/gforge-projects/#{name}/"
|
51
|
+
end
|
60
52
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
53
|
+
#about 'Public release to rubyforge'
|
54
|
+
task 'publish:gem' => [:package] do |t|
|
55
|
+
sh <<-end
|
56
|
+
rubyforge add_release -o Any -a CHANGES.txt -f -n README.md #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.gem &&
|
57
|
+
rubyforge add_file -o Any -a CHANGES.txt -f -n README.md #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.tgz
|
67
58
|
end
|
68
59
|
end
|
69
60
|
|
70
61
|
|
71
62
|
|
72
|
-
# RUBY DOCS TASK ==================================
|
73
|
-
|
74
|
-
Rake::RDocTask.new do |t|
|
75
|
-
t.rdoc_dir = 'doc'
|
76
|
-
t.title = @spec.summary
|
77
|
-
t.options << '--line-numbers' << '-A cattr_accessor=object'
|
78
|
-
t.options << '--charset' << 'utf-8'
|
79
|
-
t.rdoc_files.include(LICENSE)
|
80
|
-
t.rdoc_files.include(README)
|
81
|
-
t.rdoc_files.include(CHANGES)
|
82
|
-
t.rdoc_files.include('bin/sergeant')
|
83
|
-
t.rdoc_files.include('lib/**/*.rb')
|
84
|
-
end
|
85
|
-
|
data/VERSION.yml
ADDED
data/bin/try
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Put our local lib in first place
|
4
|
+
BASE_PATH = File.expand_path File.join(File.dirname(__FILE__), '..')
|
5
|
+
lib_dir = File.join(BASE_PATH, 'lib')
|
6
|
+
$:.unshift lib_dir
|
7
|
+
|
8
|
+
require 'tryouts'
|
9
|
+
|
10
|
+
# Help out the requires in the tryouts
|
11
|
+
[File.join(Dir.pwd, 'lib'), File.join(Dir.pwd, '..', 'lib')].each do |dir|
|
12
|
+
$:.unshift dir
|
13
|
+
end
|
14
|
+
|
15
|
+
if ARGV.empty?
|
16
|
+
paths = Dir.glob(File.join(Dir.pwd, '{try,tryouts}', '*_{try,tryouts}.rb'))
|
17
|
+
paths += Dir.glob(File.join(Dir.pwd, '*_{try,tryouts}.rb'))
|
18
|
+
else
|
19
|
+
paths = ARGV
|
20
|
+
end
|
21
|
+
|
22
|
+
#Tryouts.debug = true
|
23
|
+
#Tryouts.container = self
|
24
|
+
|
25
|
+
exit Tryouts.run_all(*paths)
|
26
|
+
|