test-spec 0.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{README.txt → README} +85 -2
- data/ROADMAP +1 -0
- data/Rakefile +105 -91
- data/TODO +2 -0
- data/bin/specrb +104 -0
- data/examples/stack.rb +38 -0
- data/examples/stack_spec.rb +119 -0
- data/lib/{test-spec/test → test}/spec.rb +167 -45
- data/lib/{test-spec/test → test}/spec/dox.rb +16 -8
- data/lib/{test-spec/test → test}/spec/rdox.rb +1 -2
- data/lib/{test-spec/test → test}/spec/should-output.rb +3 -2
- data/test/spec_dox.rb +39 -0
- data/test/spec_flexmock.rb +210 -0
- data/test/spec_mocha.rb +118 -0
- data/test/spec_nestedcontexts.rb +26 -0
- data/test/spec_should-output.rb +26 -0
- data/test/spec_testspec.rb +522 -0
- data/test/spec_testspec_order.rb +26 -0
- data/test/test_testunit.rb +21 -0
- metadata +35 -20
- data/History.txt +0 -0
- data/Manifest.txt +0 -11
- data/lib/test-spec.rb +0 -2
- data/lib/test-spec/version.rb +0 -9
- data/setup.rb +0 -1585
data/{README.txt → README}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
= test/spec, a BDD interface for Test::Unit
|
2
2
|
|
3
|
-
Copyright (C) 2006 Christian Neukirchen <mailto:chneukirchen@gmail.com>
|
3
|
+
Copyright (C) 2006, 2007 Christian Neukirchen <mailto:chneukirchen@gmail.com>
|
4
4
|
|
5
5
|
|
6
6
|
== What is test/spec?
|
@@ -95,6 +95,56 @@ If you write an useful general-purpose assertion, I'd like to hear of
|
|
95
95
|
it and may add it to the test/spec distribution.
|
96
96
|
|
97
97
|
|
98
|
+
== Messaging/Blaming
|
99
|
+
|
100
|
+
With more complex assertions, it may be helpful to provide a message
|
101
|
+
to show if the assertion has failed. This can be done with the
|
102
|
+
Should#blaming or Should#messaging methods:
|
103
|
+
|
104
|
+
RUBY_VERSION.should.messaging("Ruby too old.").be > "1.8.4"
|
105
|
+
|
106
|
+
(1 + 1).should.blaming("weird math").not.equal 11
|
107
|
+
|
108
|
+
|
109
|
+
== Custom shoulds ("Matchers")
|
110
|
+
|
111
|
+
To capture recurring patterns in parts of your specifications, you can
|
112
|
+
define custom "shoulds" (RSpec calls them "matchers") in your
|
113
|
+
contexts, or include modules of them:
|
114
|
+
|
115
|
+
context "Numbers"
|
116
|
+
class EqualString < Test::Spec::CustomShould
|
117
|
+
def matches?(other)
|
118
|
+
object == other.to_s
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def equal_string(str)
|
123
|
+
EqualString.new(str)
|
124
|
+
end
|
125
|
+
|
126
|
+
specify "should have to_s"
|
127
|
+
42.should equal_string("42")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
Alternatively, your implementation can define
|
132
|
+
CustomShould#assumptions, where you can use test/spec assertions
|
133
|
+
instead of Boolean predicates:
|
134
|
+
|
135
|
+
class EqualString < Test::Spec::CustomShould
|
136
|
+
def assumptions(other)
|
137
|
+
object.should.equal other.to_s
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
A CustomShould by default takes one argument, which is placed in
|
142
|
+
self.object for your convenience.
|
143
|
+
|
144
|
+
You can CustomShould#failure_message to provide a better error
|
145
|
+
message.
|
146
|
+
|
147
|
+
|
98
148
|
== SpecDox and RDox
|
99
149
|
|
100
150
|
test/spec adds two additional test runners to Test::Unit, based on the
|
@@ -130,6 +180,13 @@ SpecDox and RDox work for Test::Unit too:
|
|
130
180
|
3 specifications (30 requirements), 0 failures
|
131
181
|
|
132
182
|
|
183
|
+
== Disabled specifications
|
184
|
+
|
185
|
+
Akin to the usual Test::Unit practice, tests quickly can be disabled
|
186
|
+
by replacing +specify+ with +xspecify+. test/spec will count the
|
187
|
+
disabled tests when you run it with SpecDox or RDox.
|
188
|
+
|
189
|
+
|
133
190
|
== specrb
|
134
191
|
|
135
192
|
Since version 0.2, test/spec features a standalone test runner called
|
@@ -151,6 +208,18 @@ plain Test::Unit suites, too.
|
|
151
208
|
Run <tt>specrb --help</tt> for the usage.
|
152
209
|
|
153
210
|
|
211
|
+
== Installing with RubyGems
|
212
|
+
|
213
|
+
Since version 0.3, a Gem of test/spec is available. You can install with:
|
214
|
+
|
215
|
+
gem install test-spec
|
216
|
+
|
217
|
+
I also provide a local mirror of the gems (and development snapshots)
|
218
|
+
at my site:
|
219
|
+
|
220
|
+
gem install test-spec --source http://chneukirchen.org/releases/gems
|
221
|
+
|
222
|
+
|
154
223
|
== History
|
155
224
|
|
156
225
|
* September 29th, 2006: First public release 0.1.
|
@@ -163,6 +232,18 @@ Run <tt>specrb --help</tt> for the usage.
|
|
163
232
|
* Nested contexts
|
164
233
|
* Standalone test/spec runner, specrb
|
165
234
|
|
235
|
+
* January 24th, 2007: Third public release 0.3.
|
236
|
+
* should.be_close, should.be_an_instance_of, should.be_a_kind_of,
|
237
|
+
and should.be_nil have been deprecated. Use the dot-variants of
|
238
|
+
them. These assertions will be removed in 1.0.
|
239
|
+
* specrb -a now includes -Ilib by default for easier out-of-the-box
|
240
|
+
testing.
|
241
|
+
* Added custom shoulds.
|
242
|
+
* Added messaging/blaming.
|
243
|
+
* Added disabling of specifications.
|
244
|
+
* Small bug fixes.
|
245
|
+
* Gem available.
|
246
|
+
|
166
247
|
|
167
248
|
== Contact
|
168
249
|
|
@@ -176,6 +257,8 @@ http://chneukirchen.org/repos/testspec
|
|
176
257
|
== Thanks to
|
177
258
|
|
178
259
|
* Eero Saynatkari for writing <tt>should.output</tt>.
|
260
|
+
* Jean-Michel Garnier for packaging the first gem.
|
261
|
+
* Mikko Lehtonen for testing the gem.
|
179
262
|
* Thomas Fuchs for script.aculo.us BDD testing which convinced me.
|
180
263
|
* Dave Astels for BDD.
|
181
264
|
* The RSpec team for API inspiration.
|
@@ -184,7 +267,7 @@ http://chneukirchen.org/repos/testspec
|
|
184
267
|
|
185
268
|
== Copying
|
186
269
|
|
187
|
-
Copyright (C) 2006 Christian Neukirchen <http://purl.org/net/chneukirchen>
|
270
|
+
Copyright (C) 2006, 2007 Christian Neukirchen <http://purl.org/net/chneukirchen>
|
188
271
|
|
189
272
|
test/spec is licensed under the same terms as Ruby itself.
|
190
273
|
|
data/ROADMAP
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Version 1.0 (February 2006):: first stable release.
|
data/Rakefile
CHANGED
@@ -1,55 +1,6 @@
|
|
1
1
|
# Rakefile for testspec. -*-ruby-*-
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
require 'rubygems'
|
6
|
-
require 'rake'
|
7
|
-
require 'rake/clean'
|
8
|
-
require 'rake/testtask'
|
9
|
-
require 'rake/packagetask'
|
10
|
-
require 'rake/gempackagetask'
|
11
2
|
require 'rake/rdoctask'
|
12
|
-
require 'rake/
|
13
|
-
require 'fileutils'
|
14
|
-
require 'hoe'
|
15
|
-
include FileUtils
|
16
|
-
require File.join(File.dirname(__FILE__), 'lib', 'test-spec', 'version')
|
17
|
-
|
18
|
-
AUTHOR = "Christian Neukirchen" # can also be an array of Authors
|
19
|
-
EMAIL = "chneukirchen@gmail.com"
|
20
|
-
DESCRIPTION = "Behaviour Driven Development with Test::Unit"
|
21
|
-
GEM_NAME = "test-spec" # what ppl will type to install your gem
|
22
|
-
RUBYFORGE_PROJECT = "test-spec" # The unix name for your project
|
23
|
-
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
24
|
-
RELEASE_TYPES = %w( gem ) # can use: gem, tar, zip
|
25
|
-
|
26
|
-
|
27
|
-
NAME = "test-spec"
|
28
|
-
REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
29
|
-
VERS = ENV['VERSION'] || (TestSpec::VERSION::STRING + (REV ? ".#{REV}" : ""))
|
30
|
-
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
31
|
-
RDOC_OPTS = ['--quiet', '--title', "test_spec documentation",
|
32
|
-
"--opname", "index.html",
|
33
|
-
"--line-numbers",
|
34
|
-
"--main", "README",
|
35
|
-
"--inline-source"]
|
36
|
-
|
37
|
-
# Generate all the Rake tasks
|
38
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
39
|
-
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
40
|
-
p.author = AUTHOR
|
41
|
-
p.description = DESCRIPTION
|
42
|
-
p.email = EMAIL
|
43
|
-
p.summary = DESCRIPTION
|
44
|
-
p.url = HOMEPATH
|
45
|
-
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
46
|
-
p.test_globs = ["test/**/*_test.rb"]
|
47
|
-
p.clean_globs = CLEAN #An array of file patterns to delete on clean.
|
48
|
-
p.extra_deps = ['flexmock','>= 0.4.3'],['mocha','>= 0.3.2']
|
49
|
-
# == Optional
|
50
|
-
#p.changes - A description of the release's latest changes.
|
51
|
-
#p.spec_extras - A hash of extra values to set in the gemspec.
|
52
|
-
end
|
3
|
+
require 'rake/testtask'
|
53
4
|
|
54
5
|
|
55
6
|
desc "Run all the tests"
|
@@ -59,15 +10,36 @@ desc "Do predistribution stuff"
|
|
59
10
|
task :predist => [:chmod, :changelog, :rdoc]
|
60
11
|
|
61
12
|
|
62
|
-
desc "Run all the tests"
|
63
|
-
task :test => :chmod do
|
64
|
-
ruby "bin/specrb -Ilib:test -w #{ENV['TEST'] || '-a'} #{ENV['TESTOPTS']}"
|
65
|
-
end
|
66
|
-
|
67
13
|
desc "Make an archive as .tar.gz"
|
68
14
|
task :dist => :test do
|
69
15
|
system "export DARCS_REPO=#{File.expand_path "."}; " +
|
70
|
-
"darcs dist -d
|
16
|
+
"darcs dist -d test-spec#{get_darcs_tree_version}"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Helper to retrieve the "revision number" of the darcs tree.
|
20
|
+
def get_darcs_tree_version
|
21
|
+
return "" unless File.directory? "_darcs"
|
22
|
+
|
23
|
+
changes = `darcs changes`
|
24
|
+
count = 0
|
25
|
+
tag = "0.0"
|
26
|
+
|
27
|
+
changes.each("\n\n") { |change|
|
28
|
+
head, title, desc = change.split("\n", 3)
|
29
|
+
|
30
|
+
if title =~ /^ \*/
|
31
|
+
# Normal change.
|
32
|
+
count += 1
|
33
|
+
elsif title =~ /tagged (.*)/
|
34
|
+
# Tag. We look for these.
|
35
|
+
tag = $1
|
36
|
+
break
|
37
|
+
else
|
38
|
+
warn "Unparsable change: #{change}"
|
39
|
+
end
|
40
|
+
}
|
41
|
+
|
42
|
+
"-" + tag + "." + count.to_s
|
71
43
|
end
|
72
44
|
|
73
45
|
desc "Make binaries executable"
|
@@ -80,10 +52,78 @@ task :changelog do
|
|
80
52
|
system "darcs changes --repo=#{ENV["DARCS_REPO"] || "."} >ChangeLog"
|
81
53
|
end
|
82
54
|
|
55
|
+
|
56
|
+
desc "Generate RDox"
|
57
|
+
task "SPECS" do
|
58
|
+
ruby "bin/specrb -Ilib:test -a --rdox >SPECS"
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
begin
|
63
|
+
# To generate the gem, run "rake package"
|
64
|
+
|
65
|
+
$" << "sources" if defined? FromSrc
|
66
|
+
require 'rubygems'
|
67
|
+
|
68
|
+
require 'rake'
|
69
|
+
require 'rake/clean'
|
70
|
+
require 'rake/packagetask'
|
71
|
+
require 'rake/gempackagetask'
|
72
|
+
require 'rake/contrib/rubyforgepublisher'
|
73
|
+
require 'fileutils'
|
74
|
+
require 'hoe'
|
75
|
+
rescue LoadError
|
76
|
+
# Too bad.
|
77
|
+
|
78
|
+
desc "Run all the tests"
|
79
|
+
task :test => :chmod do
|
80
|
+
ruby "bin/specrb -Ilib:test -w #{ENV['TEST'] || '-a'} #{ENV['TESTOPTS']}"
|
81
|
+
end
|
82
|
+
|
83
|
+
else
|
84
|
+
|
85
|
+
RDOC_OPTS = ['--title', "test/spec documentation",
|
86
|
+
"--opname", "index.html",
|
87
|
+
"--line-numbers",
|
88
|
+
"--main", "README",
|
89
|
+
"--inline-source"]
|
90
|
+
|
91
|
+
# Generate all the Rake tasks
|
92
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
93
|
+
hoe = Hoe.new("test-spec", get_darcs_tree_version[1..-1]) do |p|
|
94
|
+
p.author = "Christian Neukirchen"
|
95
|
+
p.description = "a Behaviour Driven Development interface for Test::Unit"
|
96
|
+
p.email = "chneukirchen@gmail.com"
|
97
|
+
p.summary = <<EOF
|
98
|
+
test/spec layers an RSpec-inspired interface on top of Test::Unit, so
|
99
|
+
you can mix TDD and BDD (Behavior-Driven Development).
|
100
|
+
|
101
|
+
test/spec is a clean-room implementation that maps most kinds of
|
102
|
+
Test::Unit assertions to a `should'-like syntax.
|
103
|
+
EOF
|
104
|
+
p.url = "http://test-spec.rubyforge.org"
|
105
|
+
p.test_globs = ["test/**/{test,spec}_*.rb"]
|
106
|
+
p.clean_globs = []
|
107
|
+
p.extra_deps = ['flexmock','>= 0.4.1'],['mocha','>= 0.3.2']
|
108
|
+
p.need_tar = false # we do that ourselves
|
109
|
+
p.changes = File.read("README")[/^== History\n(.*?)^==/m, 1].
|
110
|
+
split(/\n{2,}/).last
|
111
|
+
end
|
112
|
+
|
113
|
+
task :package => ["Manifest.txt", :dist]
|
114
|
+
|
115
|
+
# Yes, this is ridiculous.
|
116
|
+
hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" }
|
117
|
+
Rake.application.instance_variable_get(:@tasks).delete :docs
|
118
|
+
Rake.application.instance_variable_get(:@tasks).delete "doc/index.html"
|
119
|
+
task :docs => :rdoc
|
120
|
+
end
|
121
|
+
|
122
|
+
|
83
123
|
desc "Generate RDoc documentation"
|
84
124
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
85
125
|
rdoc.options << '--line-numbers' << '--inline-source'
|
86
|
-
rdoc.rdoc_dir = "
|
126
|
+
rdoc.rdoc_dir = "doc"
|
87
127
|
rdoc.rdoc_files.include 'README'
|
88
128
|
rdoc.rdoc_files.include 'ROADMAP'
|
89
129
|
rdoc.rdoc_files.include 'SPECS'
|
@@ -91,47 +131,21 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
91
131
|
end
|
92
132
|
task :rdoc => "SPECS"
|
93
133
|
|
94
|
-
|
95
|
-
|
96
|
-
|
134
|
+
|
135
|
+
desc "Generate Manifest.txt"
|
136
|
+
task "Manifest.txt" do
|
137
|
+
system "darcs query manifest | sed 's:^./::' >Manifest.txt"
|
97
138
|
end
|
98
139
|
|
99
140
|
begin
|
100
141
|
require 'rcov/rcovtask'
|
101
142
|
|
102
143
|
Rcov::RcovTask.new do |t|
|
103
|
-
t.test_files = FileList['test/
|
144
|
+
t.test_files = FileList['test/{spec,test}_*.rb'] + ['--', '-rs'] # evil
|
104
145
|
t.verbose = true # uncomment to see the executed command
|
105
|
-
t.rcov_opts = ["--text-report",
|
146
|
+
t.rcov_opts = ["--text-report",
|
147
|
+
"--include-file", "^lib,^test",
|
148
|
+
"--exclude-only", "^/usr,^/home/.*/src"]
|
106
149
|
end
|
107
150
|
rescue LoadError
|
108
151
|
end
|
109
|
-
|
110
|
-
|
111
|
-
# Helper to retrieve the "revision number" of the darcs tree.
|
112
|
-
def get_darcs_tree_version
|
113
|
-
return "" unless File.directory? "_darcs"
|
114
|
-
|
115
|
-
changes = `darcs changes`
|
116
|
-
count = 0
|
117
|
-
tag = "0.0"
|
118
|
-
|
119
|
-
changes.each("\n\n") { |change|
|
120
|
-
head, title, desc = change.split("\n", 3)
|
121
|
-
|
122
|
-
if title =~ /^ \*/
|
123
|
-
# Normal change.
|
124
|
-
count += 1
|
125
|
-
elsif title =~ /tagged (.*)/
|
126
|
-
# Tag. We look for these.
|
127
|
-
tag = $1
|
128
|
-
break
|
129
|
-
else
|
130
|
-
warn "Unparsable change: #{change}"
|
131
|
-
end
|
132
|
-
}
|
133
|
-
|
134
|
-
"-" + tag + "." + count.to_s
|
135
|
-
end
|
136
|
-
|
137
|
-
|
data/TODO
ADDED
data/bin/specrb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
testrbargv = []
|
7
|
+
automatic = false
|
8
|
+
|
9
|
+
opts = OptionParser.new("", 24, ' ') { |opts|
|
10
|
+
opts.banner = "Usage: specrb [options] [files | -a] [-- untouched arguments]"
|
11
|
+
|
12
|
+
opts.separator ""
|
13
|
+
opts.separator "Ruby options:"
|
14
|
+
|
15
|
+
lineno = 1
|
16
|
+
opts.on("-e", "--eval LINE", "evaluate a LINE of code") { |line|
|
17
|
+
eval line, TOPLEVEL_BINDING, "-e", lineno
|
18
|
+
lineno += 1
|
19
|
+
}
|
20
|
+
|
21
|
+
opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") {
|
22
|
+
$DEBUG = true
|
23
|
+
}
|
24
|
+
opts.on("-w", "--warn", "turn warnings on for your script") {
|
25
|
+
$-w = true
|
26
|
+
}
|
27
|
+
|
28
|
+
opts.on("-I", "--include PATH",
|
29
|
+
"specify $LOAD_PATH (may be used more than once)") { |path|
|
30
|
+
$LOAD_PATH.unshift *path.split(":")
|
31
|
+
}
|
32
|
+
|
33
|
+
opts.on("-r", "--require LIBRARY",
|
34
|
+
"require the library, before executing your script") { |library|
|
35
|
+
require library
|
36
|
+
}
|
37
|
+
|
38
|
+
opts.separator ""
|
39
|
+
opts.separator "test/spec options:"
|
40
|
+
|
41
|
+
opts.on("-s", "--specdox", "do AgileDox-like output") {
|
42
|
+
testrbargv << "--runner=specdox"
|
43
|
+
}
|
44
|
+
opts.on("--rdox", "do AgileDox-like output with RDoc formatting") {
|
45
|
+
testrbargv << "--runner=rdox"
|
46
|
+
}
|
47
|
+
|
48
|
+
opts.on("-a", "--automatic", "gather tests from ./test/, include ./lib/") {
|
49
|
+
$LOAD_PATH.unshift "lib" if File.directory? "lib"
|
50
|
+
automatic = true
|
51
|
+
}
|
52
|
+
|
53
|
+
opts.separator ""
|
54
|
+
opts.separator "test/unit options:"
|
55
|
+
|
56
|
+
opts.on('-n', '--name NAME', String,
|
57
|
+
"runs tests matching regexp NAME") { |n|
|
58
|
+
testrbargv << "-n" << "/#{n}/"
|
59
|
+
}
|
60
|
+
|
61
|
+
opts.on('-t', '--testcase TESTCASE', String,
|
62
|
+
"runs tests in TestCases matching regexp TESTCASE") { |t|
|
63
|
+
testrbargv << "-t" << "/#{t}/"
|
64
|
+
}
|
65
|
+
|
66
|
+
opts.separator ""
|
67
|
+
opts.separator "Common options:"
|
68
|
+
|
69
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
70
|
+
puts opts
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
|
74
|
+
opts.on_tail("--version", "Show version") do
|
75
|
+
require 'test/spec'
|
76
|
+
puts "specrb #{Test::Spec::VERSION}"
|
77
|
+
exit
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.parse! ARGV
|
81
|
+
}
|
82
|
+
|
83
|
+
files = ARGV
|
84
|
+
|
85
|
+
if automatic
|
86
|
+
files.concat Dir["test/test_*.rb"]
|
87
|
+
files.concat Dir["test/spec_*.rb"]
|
88
|
+
files.concat Dir["spec/spec_*.rb"]
|
89
|
+
end
|
90
|
+
|
91
|
+
if files.empty?
|
92
|
+
puts opts.banner
|
93
|
+
exit 1
|
94
|
+
end
|
95
|
+
|
96
|
+
argv = testrbargv + ["--"] + files
|
97
|
+
|
98
|
+
require 'test/spec'
|
99
|
+
|
100
|
+
Test::Unit.run = false
|
101
|
+
runner = Test::Unit::AutoRunner.new true
|
102
|
+
runner.process_args(argv) ||
|
103
|
+
abort("internal error calling Test::Unit, please report a bug")
|
104
|
+
exit runner.run
|