nullstyle-test-spec 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ Manifest.txt
2
+ README
3
+ Rakefile
4
+ test-spec.gemspec
5
+ lib/test/spec.rb
6
+ lib/test/spec/dox.rb
7
+ lib/test/spec/rdox.rb
8
+ lib/test/spec/should-output.rb
9
+ lib/test/spec/version.rb
10
+ test/spec_dox.rb
11
+ test/spec_flexmock.rb
12
+ test/spec_mocha.rb
13
+ test/spec_nestedcontexts.rb
14
+ test/spec_new_style.rb
15
+ test/spec_should-output.rb
16
+ test/spec_testspec.rb
17
+ test/spec_testspec_order.rb
18
+ test/test_testunit.rb
data/README ADDED
@@ -0,0 +1,376 @@
1
+ = test/spec, a BDD interface for Test::Unit
2
+
3
+ Copyright (C) 2006, 2007 Christian Neukirchen <mailto:chneukirchen@gmail.com>
4
+
5
+
6
+ == What is test/spec?
7
+
8
+ test/spec layers an RSpec-inspired interface on top of Test::Unit, so
9
+ you can mix TDD and BDD (Behavior-Driven Development).
10
+
11
+ test/spec is a clean-room implementation that maps most kinds of
12
+ Test::Unit assertions to a `should'-like syntax.
13
+
14
+ Consider this Test::Unit test case:
15
+
16
+ class TestFoo < Test::Unit::TestCase
17
+ def test_should_bar
18
+ assert_equal 5, 2 + 3
19
+ end
20
+ end
21
+
22
+ In test/spec, it looks like this:
23
+
24
+ require 'test/spec'
25
+
26
+ context "Foo" do
27
+ specify "should bar" do
28
+ (2 + 3).should.equal 5
29
+ end
30
+ end
31
+
32
+ Since test/spec 0.4, you can also use the new RSpec 1.0 style:
33
+
34
+ require 'test/spec'
35
+
36
+ describe "Foo" do
37
+ it "should bar" do
38
+ (2 + 3).should.equal 5
39
+ end
40
+ end
41
+
42
+ test/spec does not include a mocking/stubbing-framework; use whichever
43
+ you like to. test/spec has been tested successfully with FlexMock and
44
+ Mocha.
45
+
46
+ test/spec has no dependencies outside Ruby 1.8.
47
+
48
+
49
+ == Mixing test/spec and test/unit
50
+
51
+ test/spec and Test::Unit contexts/test cases can be intermixed freely,
52
+ run in the same test and live in the same files. You can just add them
53
+ to your Rake::TestTask, too. test/spec allows you to leverage your
54
+ full existing Test::Unit infrastructure.
55
+
56
+ test/spec does not change Test::Unit with the exception of
57
+ monkey-patching Test::Unit::TestSuite to order the test cases before
58
+ running them. (This should not do any harm, but if you know a way
59
+ around it, please tell me.)
60
+
61
+ test/spec adds three global methods, Object#should, Kernel.context,
62
+ and Kernel.describe.
63
+
64
+ You can use <tt>assert_*</tt> freely in specify-blocks; Object#should
65
+ works in plain Test::Unit test cases, too, but they will not be counted.
66
+
67
+
68
+ == Wrapped assertions
69
+
70
+ +assert_equal+:: <tt>should.equal</tt>, <tt>should ==</tt>
71
+ +assert_not_equal+:: <tt>should.not.equal</tt>, <tt>should.not ==</tt>
72
+ +assert_same+:: <tt>should.be</tt>
73
+ +assert_not_same+:: <tt>should.not.be</tt>
74
+ +assert_nil+:: <tt>should.be.nil</tt>
75
+ +assert_not_nil+:: <tt>should.not.be.nil</tt>
76
+ +assert_in_delta+:: <tt>should.be.close</tt>
77
+ +assert_match+:: <tt>should.match</tt>, <tt>should =~</tt>
78
+ +assert_no_match+:: <tt>should.not.match</tt>, <tt>should.not =~</tt>
79
+
80
+ +assert_instance_of+:: <tt>should.be.an.instance_of</tt>
81
+ +assert_kind_of+:: <tt>should.be.a.kind_of</tt>
82
+ +assert_respond_to+:: <tt>should.respond_to</tt>
83
+ +assert_raise+:: <tt>should.raise</tt>
84
+ +assert_nothing_raised+:: <tt>should.not.raise</tt>
85
+ +assert_throws+:: <tt>should.throw</tt>
86
+ +assert_nothing_thrown+:: <tt>should.not.throw</tt>
87
+
88
+ +assert_block+:: <tt>should.satisfy</tt>
89
+
90
+ (+a+, +an+ and +be+ without arguments are optional and no-ops.)
91
+
92
+
93
+ == Additional assertions
94
+
95
+ These assertions are not included in Test::Unit, but have been added
96
+ to test/spec for convenience:
97
+
98
+ * <tt>should.not.satisfy</tt>
99
+ * <tt>should.include</tt>
100
+ * <tt>a.should.</tt>_predicate_ (works like <tt>assert
101
+ a.</tt>_predicate_<tt>?</tt>)
102
+ * <tt>a.should.be </tt>_operator_ (where _operator_ is one of <tt>></tt>, <tt>>=</tt>, <tt><</tt>, <tt><=</tt> or <tt>===</tt>)
103
+ * <tt>should.output</tt> (require test/spec/should-output)
104
+
105
+ If you write an useful general-purpose assertion, I'd like to hear of
106
+ it and may add it to the test/spec distribution.
107
+
108
+
109
+ == Messaging/Blaming
110
+
111
+ With more complex assertions, it may be helpful to provide a message
112
+ to show if the assertion has failed. This can be done with the
113
+ Should#blaming or Should#messaging methods:
114
+
115
+ RUBY_VERSION.should.messaging("Ruby too old.").be > "1.8.4"
116
+
117
+ (1 + 1).should.blaming("weird math").not.equal 11
118
+
119
+
120
+ == Custom shoulds ("Matchers")
121
+
122
+ To capture recurring patterns in parts of your specifications, you can
123
+ define custom "shoulds" (RSpec calls them "matchers") in your
124
+ contexts, or include modules of them:
125
+
126
+ context "Numbers"
127
+ class EqualString < Test::Spec::CustomShould
128
+ def matches?(other)
129
+ object == other.to_s
130
+ end
131
+ end
132
+
133
+ def equal_string(str)
134
+ EqualString.new(str)
135
+ end
136
+
137
+ specify "should have to_s"
138
+ 42.should equal_string("42")
139
+ end
140
+ end
141
+
142
+ Alternatively, your implementation can define
143
+ CustomShould#assumptions, where you can use test/spec assertions
144
+ instead of Boolean predicates:
145
+
146
+ class EqualString < Test::Spec::CustomShould
147
+ def assumptions(other)
148
+ object.should.equal other.to_s
149
+ end
150
+ end
151
+
152
+ A CustomShould by default takes one argument, which is placed in
153
+ self.object for your convenience.
154
+
155
+ You can CustomShould#failure_message to provide a better error
156
+ message.
157
+
158
+
159
+ == SpecDox and RDox
160
+
161
+ test/spec adds two additional test runners to Test::Unit, based on the
162
+ console runner but with a different output format.
163
+
164
+ SpecDox, run with <tt>--runner=specdox</tt> (or <tt>-rs</tt>) looks
165
+ like RSpec's output:
166
+
167
+ should.output
168
+ - works for print
169
+ - works for puts
170
+ - works with readline
171
+
172
+ RDox, run with <tt>--runner=rdox</tt> (or <tt>-rr</tt>) can be
173
+ included for RDoc documentation (e.g. see SPECS):
174
+
175
+ == should.output
176
+ * works for print
177
+ * works for puts
178
+ * works with readline
179
+
180
+ SpecDox and RDox work for Test::Unit too:
181
+
182
+ $ ruby -r test/spec test/testunit/test_testresult.rb -rs
183
+
184
+ Test::Unit::TC_TestResult
185
+ - fault notification
186
+ - passed?
187
+ - result changed notification
188
+
189
+ Finished in 0.106647 seconds.
190
+
191
+ 3 specifications (30 requirements), 0 failures
192
+
193
+ Since version 0.4, SpecDox and RDox also notice and count empty
194
+ specifications.
195
+
196
+
197
+ == Disabled specifications
198
+
199
+ Akin to the usual Test::Unit practice, tests quickly can be disabled
200
+ by replacing +specify+ with +xspecify+ (or +it+ with +xit+).
201
+ test/spec will count the disabled tests when you run it with SpecDox
202
+ or RDox.
203
+
204
+ When you use xspecify/xit, you also can drop the block. This is
205
+ useful for writing specifications that you haven't yet started
206
+ implementing.
207
+
208
+ Complete contexts can be disabled by using +xcontext+/+xdescribe+.
209
+
210
+
211
+ == Setup/Teardown
212
+
213
+ Setup/Teardown methods are run in this order:
214
+
215
+ * before(:all) in order of definition
216
+ * before(:each)/setup in order of definition
217
+ * specify
218
+ * after(:each)/setup in order of definition
219
+ * before(:each)/setup in order of definition
220
+ * specify
221
+ * after(:each)/setup in order of definition
222
+ * ...
223
+ * after(:all) in order of definition
224
+
225
+ Please note that before(:all) and after(:all) are run in their own
226
+ instance, so all instance variables they set are lost(!) and not
227
+ visible to other specifications. They are e.g. useful for setting up
228
+ database connections or starting servers.
229
+
230
+
231
+ == Shared contexts
232
+
233
+ Since version 0.5, you can define shared contexts in test/spec using
234
+ shared_context/describe_shared. These contexts are not executed on
235
+ their own, but can be included with it_should_behave_like/behaves_like
236
+ in other contexts. You can use shared contexts to structure suites
237
+ with many recurring specifications.
238
+
239
+
240
+ == specrb
241
+
242
+ Since version 0.2, test/spec features a standalone test runner called
243
+ specrb. specrb is like an extended version of testrb, Test::Unit's
244
+ test runner, but has additional options. It can be used for
245
+ plain Test::Unit suites, too.
246
+
247
+ $ specrb -a -s -n should.output
248
+
249
+ should.output
250
+ - works for print
251
+ - works for puts
252
+ - works with readline
253
+
254
+ Finished in 0.162571 seconds.
255
+
256
+ 3 specifications (6 requirements), 0 failures
257
+
258
+ Run <tt>specrb --help</tt> for the usage.
259
+
260
+
261
+ == test/spec on Rails
262
+
263
+ If you want to specify your Rails applications, you can use the third-party
264
+ plugin "test/spec on Rails", which can be found at:
265
+
266
+ http://svn.techno-weenie.net/projects/plugins/test_spec_on_rails/
267
+
268
+ It features testing of model validation, redirection, output, HTTP
269
+ status, template rendering and URL generation.
270
+
271
+
272
+ == Installing with RubyGems
273
+
274
+ Since version 0.3, a Gem of test/spec is available. You can install with:
275
+
276
+ gem install test-spec
277
+
278
+ I also provide a local mirror of the gems (and development snapshots)
279
+ at my site:
280
+
281
+ gem install test-spec --source http://chneukirchen.org/releases/gems
282
+
283
+
284
+ == History
285
+
286
+ * September 29th, 2006: First public release 0.1.
287
+
288
+ * October 18th, 2006: Second public release 0.2.
289
+ * Better, module-based implementation
290
+ * Official support for FlexMock and Mocha
291
+ * More robust Should#output
292
+ * Should#_operator_
293
+ * Nested contexts
294
+ * Standalone test/spec runner, specrb
295
+
296
+ * January 24th, 2007: Third public release 0.3.
297
+ * should.be_close, should.be_an_instance_of, should.be_a_kind_of,
298
+ and should.be_nil have been deprecated. Use the dot-variants of
299
+ them. These assertions will be removed in 1.0.
300
+ * specrb -a now includes -Ilib by default for easier out-of-the-box
301
+ testing.
302
+ * Added custom shoulds.
303
+ * Added messaging/blaming.
304
+ * Added disabling of specifications.
305
+ * Small bug fixes.
306
+ * Gem available.
307
+
308
+ * June 29th, 2007: Fourth public release 0.4.
309
+ * Support for Ruby 1.8.6.
310
+ * Support describe/it/before/after RSpec 1.0 syntax.
311
+ * Allow should.raise { code_that_raises }
312
+ * Add xcontext to disable complete contexts.
313
+ * Backtraces are cleaner now.
314
+ * Mention test/spec on Rails.
315
+ * Fix small Gem bugs.
316
+ * Fix bug related to counting negated assertions.
317
+ * Fix bug in specrb.
318
+ * Allow empty xspecifys.
319
+ * Make SpecDox and RDox count empty specifications.
320
+ * Allow Kernel#context to take a superclass.
321
+
322
+ * XXX, 2007: Fifth public release 0.5.
323
+ * Allow should.<predicate>? as well as should.<predicate>.
324
+ * Add shared contexts.
325
+ * Nested contexts now run the
326
+ setups/teardowns/before(:all)/after(:all) of their parents.
327
+
328
+
329
+ == Contact
330
+
331
+ Please mail bugs, suggestions and patches to
332
+ <mailto:chneukirchen@gmail.com>.
333
+
334
+ Darcs repository ("darcs send" is welcome for patches):
335
+ http://chneukirchen.org/repos/testspec
336
+
337
+
338
+ == Thanks to
339
+
340
+ * Eero Saynatkari for writing <tt>should.output</tt>.
341
+ * Tuxie for writing test/spec on Rails.
342
+ * Brian Donovan for allowing alternative superclasses.
343
+ * Xavier Shay for implementing nested setups/teardowns.
344
+ * Chris Wanstrath for <tt>should.raise</tt> with a block and <tt>xcontext</tt>.
345
+ * Jean-Michel Garnier for packaging the first gem.
346
+ * Mikko Lehtonen, Jan Wikholm, Matt Mower and Michael Fellinger for
347
+ testing the gem.
348
+ * Chris McGrath for reporting a bug.
349
+ * Thomas Fuchs for script.aculo.us BDD testing which convinced me.
350
+ * Dave Astels for BDD.
351
+ * The RSpec team for API inspiration.
352
+ * Nathaniel Talbott for Test::Unit.
353
+
354
+
355
+ == Copying
356
+
357
+ Copyright (C) 2006, 2007 Christian Neukirchen <http://purl.org/net/chneukirchen>
358
+
359
+ test/spec is licensed under the same terms as Ruby itself.
360
+
361
+ Please mail bugs, feature requests or patches to the mail addresses
362
+ found above or use IRC[irc://freenode.net/#ruby-lang] to contact the
363
+ developer.
364
+
365
+
366
+ == Links
367
+
368
+ Behavior-Driven Development:: <http://behaviour-driven.org/>
369
+ RSpec:: <http://rspec.rubyforge.org/>
370
+ script.aculo.us testing:: <http://mir.aculo.us/articles/2006/08/29/bdd-style-javascript-testing>
371
+
372
+ FlexMock:: <http://onestepback.org/software/flexmock/>
373
+ Mocha:: <http://mocha.rubyforge.org/>
374
+
375
+ Christian Neukirchen:: <http://chneukirchen.org/>
376
+
@@ -0,0 +1,165 @@
1
+ # Rakefile for testspec. -*-ruby-*-
2
+ require 'rake/rdoctask'
3
+ require 'rake/testtask'
4
+
5
+
6
+ desc "Run all the tests"
7
+ task :default => [:test]
8
+
9
+ desc "Do predistribution stuff"
10
+ task :predist => [:chmod, :changelog, :rdoc, :distmanifest]
11
+
12
+
13
+ desc "Make an archive as .tar.gz"
14
+ task :dist => :test do
15
+ system "export DARCS_REPO=#{File.expand_path "."}; " +
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
+ unless File.directory? "_darcs"
22
+ load 'lib/test/spec/version.rb'
23
+ return Test::Spec::VERSION
24
+ end
25
+
26
+ changes = `darcs changes`
27
+ count = 0
28
+ tag = "0.0"
29
+
30
+ changes.each("\n\n") { |change|
31
+ head, title, desc = change.split("\n", 3)
32
+
33
+ if title =~ /^ \*/
34
+ # Normal change.
35
+ count += 1
36
+ elsif title =~ /tagged (.*)/
37
+ # Tag. We look for these.
38
+ tag = $1
39
+ break
40
+ else
41
+ warn "Unparsable change: #{change}"
42
+ end
43
+ }
44
+
45
+ tag + "." + count.to_s
46
+ end
47
+
48
+
49
+ desc "Make binaries executable"
50
+ task :chmod do
51
+ Dir["bin/*"].each { |binary| File.chmod(0775, binary) }
52
+ end
53
+
54
+ desc "Generate a ChangeLog"
55
+ task :changelog do
56
+ system "darcs changes --repo=#{ENV["DARCS_REPO"] || "."} >ChangeLog"
57
+ end
58
+
59
+
60
+ desc "Generate RDox"
61
+ task "SPECS" do
62
+ ruby "bin/specrb -Ilib:test -a --rdox >SPECS"
63
+ end
64
+
65
+
66
+ begin
67
+ # To generate the gem, run "rake package"
68
+
69
+ $" << "sources" if defined? FromSrc
70
+ require 'rubygems'
71
+
72
+ require 'rake'
73
+ require 'rake/clean'
74
+ require 'rake/packagetask'
75
+ require 'rake/gempackagetask'
76
+ require 'rake/contrib/rubyforgepublisher'
77
+ require 'fileutils'
78
+ require 'hoe'
79
+ rescue LoadError
80
+ # Too bad.
81
+
82
+ desc "Run all the tests"
83
+ task :test => :chmod do
84
+ ruby "bin/specrb -Ilib:test -w #{ENV['TEST'] || '-a'} #{ENV['TESTOPTS']}"
85
+ end
86
+
87
+ else
88
+
89
+ RDOC_OPTS = ['--title', "test/spec documentation",
90
+ "--opname", "index.html",
91
+ "--line-numbers",
92
+ "--main", "README",
93
+ "--inline-source"]
94
+
95
+ # Generate all the Rake tasks
96
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
97
+ hoe = Hoe.new("test-spec", get_darcs_tree_version) do |p|
98
+ p.author = "Christian Neukirchen"
99
+ p.description = "a Behaviour Driven Development interface for Test::Unit"
100
+ p.email = "chneukirchen@gmail.com"
101
+ p.summary = <<EOF
102
+ test/spec layers an RSpec-inspired interface on top of Test::Unit, so
103
+ you can mix TDD and BDD (Behavior-Driven Development).
104
+
105
+ test/spec is a clean-room implementation that maps most kinds of
106
+ Test::Unit assertions to a `should'-like syntax.
107
+ EOF
108
+ p.url = "http://test-spec.rubyforge.org"
109
+ p.test_globs = ["test/**/{test,spec}_*.rb"]
110
+ p.clean_globs = []
111
+ # These are actually optional, but we can't tell Gems that.
112
+ # p.extra_deps = ['flexmock','>= 0.4.1'],['mocha','>= 0.3.2']
113
+ p.need_tar = false # we do that ourselves
114
+ p.changes = File.read("README")[/^== History\n(.*?)^==/m, 1].
115
+ split(/\n{2,}/).last
116
+ end rescue nil
117
+
118
+ task :package => ["Manifest.txt", :dist]
119
+
120
+ # Yes, this is ridiculous.
121
+ hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" } if hoe
122
+ Rake.application.instance_variable_get(:@tasks).delete :docs
123
+ Rake.application.instance_variable_get(:@tasks).delete "doc/index.html"
124
+ task :docs => :rdoc
125
+ end
126
+
127
+
128
+ desc "Generate RDoc documentation"
129
+ Rake::RDocTask.new(:rdoc) do |rdoc|
130
+ rdoc.options << '--line-numbers' << '--inline-source'
131
+ rdoc.rdoc_dir = "doc"
132
+ rdoc.rdoc_files.include 'README'
133
+ rdoc.rdoc_files.include 'ROADMAP'
134
+ rdoc.rdoc_files.include 'SPECS'
135
+ rdoc.rdoc_files.include('lib/**/*.rb')
136
+ end
137
+ task :rdoc => "SPECS"
138
+
139
+
140
+ desc "Generate Manifest.txt"
141
+ task "Manifest.txt" do
142
+ system "darcs query manifest | sed 's:^./::' >Manifest.txt"
143
+ end
144
+
145
+ desc "Generate Manifest.txt for dist"
146
+ task :distmanifest do
147
+ File.open("Manifest.txt", "wb") { |manifest|
148
+ Dir["**/*"].each { |file|
149
+ manifest.puts file if File.file? file
150
+ }
151
+ }
152
+ end
153
+
154
+ begin
155
+ require 'rcov/rcovtask'
156
+
157
+ Rcov::RcovTask.new do |t|
158
+ t.test_files = FileList['test/{spec,test}_*.rb'] + ['--', '-rs'] # evil
159
+ t.verbose = true # uncomment to see the executed command
160
+ t.rcov_opts = ["--text-report",
161
+ "--include-file", "^lib,^test",
162
+ "--exclude-only", "^/usr,^/home/.*/src"]
163
+ end
164
+ rescue LoadError
165
+ end