test-spec 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -29,6 +29,16 @@ In test/spec, it looks like this:
29
29
  end
30
30
  end
31
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
+
32
42
  test/spec does not include a mocking/stubbing-framework; use whichever
33
43
  you like to. test/spec has been tested successfully with FlexMock and
34
44
  Mocha.
@@ -48,7 +58,8 @@ monkey-patching Test::Unit::TestSuite to order the test cases before
48
58
  running them. (This should not do any harm, but if you know a way
49
59
  around it, please tell me.)
50
60
 
51
- test/spec adds two global methods, Object#should and Kernel.context.
61
+ test/spec adds three global methods, Object#should, Kernel.context,
62
+ and Kernel.describe.
52
63
 
53
64
  You can use <tt>assert_*</tt> freely in specify-blocks; Object#should
54
65
  works in plain Test::Unit test cases, too, but they will not be counted.
@@ -179,12 +190,42 @@ SpecDox and RDox work for Test::Unit too:
179
190
 
180
191
  3 specifications (30 requirements), 0 failures
181
192
 
193
+ Since version 0.4, SpecDox and RDox also notice and count empty
194
+ specifications.
195
+
182
196
 
183
197
  == Disabled specifications
184
198
 
185
199
  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.
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.
188
229
 
189
230
 
190
231
  == specrb
@@ -208,6 +249,17 @@ plain Test::Unit suites, too.
208
249
  Run <tt>specrb --help</tt> for the usage.
209
250
 
210
251
 
252
+ == test/spec on Rails
253
+
254
+ If you want to specify your Rails applications, you can use the third-party
255
+ plugin "test/spec on Rails", which can be found at:
256
+
257
+ http://svn.techno-weenie.net/projects/plugins/test_spec_on_rails/
258
+
259
+ It features testing of model validation, redirection, output, HTTP
260
+ status, template rendering and URL generation.
261
+
262
+
211
263
  == Installing with RubyGems
212
264
 
213
265
  Since version 0.3, a Gem of test/spec is available. You can install with:
@@ -244,6 +296,20 @@ at my site:
244
296
  * Small bug fixes.
245
297
  * Gem available.
246
298
 
299
+ * June 29th, 2007: Fourth public release 0.4.
300
+ * Support for Ruby 1.8.6.
301
+ * Support describe/it/before/after RSpec 1.0 syntax.
302
+ * Allow should.raise { code_that_raises }
303
+ * Add xcontext to disable complete contexts.
304
+ * Backtraces are cleaner now.
305
+ * Mention test/spec on Rails.
306
+ * Fix small Gem bugs.
307
+ * Fix bug related to counting negated assertions.
308
+ * Fix bug in specrb.
309
+ * Allow empty xspecifys.
310
+ * Make SpecDox and RDox count empty specifications.
311
+ * Allow Kernel#context to take a superclass.
312
+
247
313
 
248
314
  == Contact
249
315
 
@@ -257,8 +323,13 @@ http://chneukirchen.org/repos/testspec
257
323
  == Thanks to
258
324
 
259
325
  * Eero Saynatkari for writing <tt>should.output</tt>.
326
+ * Tuxie for writing test/spec on Rails.
327
+ * Brian Donovan for allowing alternative superclasses.
328
+ * Chris Wanstrath for <tt>should.raise</tt> with a block and <tt>xcontext</tt>.
260
329
  * Jean-Michel Garnier for packaging the first gem.
261
- * Mikko Lehtonen for testing the gem.
330
+ * Mikko Lehtonen, Jan Wikholm, Matt Mower and Michael Fellinger for
331
+ testing the gem.
332
+ * Chris McGrath for reporting a bug.
262
333
  * Thomas Fuchs for script.aculo.us BDD testing which convinced me.
263
334
  * Dave Astels for BDD.
264
335
  * The RSpec team for API inspiration.
data/Rakefile CHANGED
@@ -7,18 +7,21 @@ desc "Run all the tests"
7
7
  task :default => [:test]
8
8
 
9
9
  desc "Do predistribution stuff"
10
- task :predist => [:chmod, :changelog, :rdoc]
10
+ task :predist => [:chmod, :changelog, :rdoc, :distmanifest]
11
11
 
12
12
 
13
13
  desc "Make an archive as .tar.gz"
14
14
  task :dist => :test do
15
15
  system "export DARCS_REPO=#{File.expand_path "."}; " +
16
- "darcs dist -d test-spec#{get_darcs_tree_version}"
16
+ "darcs dist -d test-spec-#{get_darcs_tree_version}"
17
17
  end
18
18
 
19
19
  # Helper to retrieve the "revision number" of the darcs tree.
20
20
  def get_darcs_tree_version
21
- return "" unless File.directory? "_darcs"
21
+ unless File.directory? "_darcs"
22
+ load 'lib/test/spec/version.rb'
23
+ return Test::Spec::VERSION
24
+ end
22
25
 
23
26
  changes = `darcs changes`
24
27
  count = 0
@@ -39,9 +42,10 @@ def get_darcs_tree_version
39
42
  end
40
43
  }
41
44
 
42
- "-" + tag + "." + count.to_s
45
+ tag + "." + count.to_s
43
46
  end
44
47
 
48
+
45
49
  desc "Make binaries executable"
46
50
  task :chmod do
47
51
  Dir["bin/*"].each { |binary| File.chmod(0775, binary) }
@@ -90,7 +94,7 @@ else
90
94
 
91
95
  # Generate all the Rake tasks
92
96
  # 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|
97
+ hoe = Hoe.new("test-spec", get_darcs_tree_version) do |p|
94
98
  p.author = "Christian Neukirchen"
95
99
  p.description = "a Behaviour Driven Development interface for Test::Unit"
96
100
  p.email = "chneukirchen@gmail.com"
@@ -104,16 +108,17 @@ EOF
104
108
  p.url = "http://test-spec.rubyforge.org"
105
109
  p.test_globs = ["test/**/{test,spec}_*.rb"]
106
110
  p.clean_globs = []
107
- p.extra_deps = ['flexmock','>= 0.4.1'],['mocha','>= 0.3.2']
111
+ # These are actually optional, but we can't tell Gems that.
112
+ # p.extra_deps = ['flexmock','>= 0.4.1'],['mocha','>= 0.3.2']
108
113
  p.need_tar = false # we do that ourselves
109
114
  p.changes = File.read("README")[/^== History\n(.*?)^==/m, 1].
110
115
  split(/\n{2,}/).last
111
- end
116
+ end rescue nil
112
117
 
113
118
  task :package => ["Manifest.txt", :dist]
114
119
 
115
120
  # Yes, this is ridiculous.
116
- hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" }
121
+ hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" } if hoe
117
122
  Rake.application.instance_variable_get(:@tasks).delete :docs
118
123
  Rake.application.instance_variable_get(:@tasks).delete "doc/index.html"
119
124
  task :docs => :rdoc
@@ -137,6 +142,15 @@ task "Manifest.txt" do
137
142
  system "darcs query manifest | sed 's:^./::' >Manifest.txt"
138
143
  end
139
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
+
140
154
  begin
141
155
  require 'rcov/rcovtask'
142
156
 
data/TODO CHANGED
@@ -1,2 +1,3 @@
1
1
  - see ROADMAP
2
2
  - better handling of .should outside of specify(?)
3
+ - shared behaviors?
data/bin/specrb CHANGED
@@ -27,7 +27,7 @@ opts = OptionParser.new("", 24, ' ') { |opts|
27
27
 
28
28
  opts.on("-I", "--include PATH",
29
29
  "specify $LOAD_PATH (may be used more than once)") { |path|
30
- $LOAD_PATH.unshift *path.split(":")
30
+ $LOAD_PATH.unshift(*path.split(":"))
31
31
  }
32
32
 
33
33
  opts.on("-r", "--require LIBRARY",
@@ -93,7 +93,10 @@ if files.empty?
93
93
  exit 1
94
94
  end
95
95
 
96
- argv = testrbargv + ["--"] + files
96
+ argv = testrbargv + files
97
+ # Should use -- to separate them *but* there's a bug in
98
+ # Test::Unit::AutoRunner#process_args: arguments after -- are ignored.
99
+ # (You could also argue that it's a bug in optparse.rb).
97
100
 
98
101
  require 'test/spec'
99
102
 
data/lib/test/spec.rb CHANGED
@@ -24,8 +24,8 @@ module Test # :nodoc:
24
24
  end
25
25
 
26
26
  module Test::Spec
27
- VERSION = "0.3"
28
-
27
+ require 'test/spec/version'
28
+
29
29
  CONTEXTS = {} # :nodoc:
30
30
 
31
31
  class DefinitionError < StandardError
@@ -127,9 +127,10 @@ module Test::Spec
127
127
  assert_respond_to @object, method, @message
128
128
  end
129
129
 
130
- def _raise(*args)
130
+ def _raise(*args, &block)
131
131
  args = [RuntimeError] if args.empty?
132
- assert_raise(*(args + [@message]), &@object)
132
+ block ||= @object
133
+ assert_raise(*(args + [@message]), &block)
133
134
  end
134
135
 
135
136
  def throw(*args)
@@ -177,9 +178,9 @@ module Test::Spec
177
178
  }
178
179
  end
179
180
 
180
- def method_missing(name, *args)
181
+ def method_missing(name, *args, &block)
181
182
  # This will make raise call Kernel.raise, and self.raise call _raise.
182
- return _raise(*args) if name == :raise
183
+ return _raise(*args, &block) if name == :raise
183
184
 
184
185
  if @object.respond_to?("#{name}?")
185
186
  assert @object.__send__("#{name}?", *args),
@@ -198,6 +199,11 @@ module Test::Spec
198
199
  @message = message
199
200
  end
200
201
 
202
+ def add_assertion
203
+ $TEST_SPEC_TESTCASE && $TEST_SPEC_TESTCASE.__send__(:add_assertion)
204
+ end
205
+
206
+
201
207
  def satisfy(&block)
202
208
  assert_block(@message || "not.satisfy block succeded.") {
203
209
  not yield @object
@@ -230,8 +236,9 @@ module Test::Spec
230
236
  end
231
237
  alias =~ match
232
238
 
233
- def _raise(*args)
234
- assert_nothing_raised(*(args+[@message]), &@object)
239
+ def _raise(*args, &block)
240
+ block ||= @object
241
+ assert_nothing_raised(*(args+[@message]), &block)
235
242
  end
236
243
 
237
244
  def throw
@@ -266,9 +273,9 @@ module Test::Spec
266
273
  }
267
274
  end
268
275
 
269
- def method_missing(name, *args)
276
+ def method_missing(name, *args, &block)
270
277
  # This will make raise call Kernel.raise, and self.raise call _raise.
271
- return _raise(*args) if name == :raise
278
+ return _raise(*args, &block) if name == :raise
272
279
 
273
280
  if @object.respond_to?("#{name}?")
274
281
  assert_block("#{name}? expected to be false. #{@message}") {
@@ -319,13 +326,21 @@ class Test::Spec::TestCase
319
326
  super
320
327
  self.class.teardowns.each { |t| instance_eval(&t) }
321
328
  end
329
+
330
+ def before_all
331
+ self.class.before_all.each { |t| instance_eval(&t) }
332
+ end
333
+
334
+ def after_all
335
+ self.class.after_all.each { |t| instance_eval(&t) }
336
+ end
322
337
 
323
338
  def initialize(name)
324
339
  super name
325
340
 
326
341
  # Don't let the default_test clutter up the results and don't
327
342
  # flunk if no tests given, either.
328
- throw :invalid_test if name == :default_test
343
+ throw :invalid_test if name.to_s == "default_test"
329
344
  end
330
345
 
331
346
  def position
@@ -336,6 +351,8 @@ class Test::Spec::TestCase
336
351
  raise Test::Spec::DefinitionError,
337
352
  "context definition is not allowed inside a specify-block"
338
353
  end
354
+
355
+ alias :describe :context
339
356
  end
340
357
 
341
358
  module ClassMethods
@@ -347,9 +364,17 @@ class Test::Spec::TestCase
347
364
  attr_accessor :setups
348
365
  attr_accessor :teardowns
349
366
 
350
- def context(name, &block)
351
- (Test::Spec::CONTEXTS[self.name + "\t" + name] ||=
352
- Test::Spec::TestCase.new(name, self)).add(&block)
367
+ attr_accessor :before_all
368
+ attr_accessor :after_all
369
+
370
+ # old-style (RSpec <1.0):
371
+
372
+ def context(name, superclass=Test::Unit::TestCase, klass=Test::Spec::TestCase, &block)
373
+ (Test::Spec::CONTEXTS[self.name + "\t" + name] ||= klass.new(name, self, superclass)).add(&block)
374
+ end
375
+
376
+ def xcontext(name, superclass=Test::Unit::TestCase, &block)
377
+ context(name, superclass, Test::Spec::DisabledTestCase, &block)
353
378
  end
354
379
 
355
380
  def specify(specname, &block)
@@ -361,8 +386,6 @@ class Test::Spec::TestCase
361
386
  end
362
387
 
363
388
  def xspecify(specname, &block)
364
- raise ArgumentError, "xspecify needs a block" if block.nil?
365
-
366
389
  specify specname do
367
390
  @_result.add_disabled(specname)
368
391
  end
@@ -376,6 +399,35 @@ class Test::Spec::TestCase
376
399
  teardowns << block
377
400
  end
378
401
 
402
+ # new-style (RSpec 1.0+):
403
+
404
+ alias :describe :context
405
+ alias :it :specify
406
+ alias :xit :xspecify
407
+
408
+ def before(kind=:each, &block)
409
+ case kind
410
+ when :each
411
+ setup(&block)
412
+ when :all
413
+ before_all << block
414
+ else
415
+ raise ArgumentError, "invalid argument: before(#{kind.inspect})"
416
+ end
417
+ end
418
+
419
+ def after(kind=:each, &block)
420
+ case kind
421
+ when :each
422
+ teardown(&block)
423
+ when :all
424
+ after_all << block
425
+ else
426
+ raise ArgumentError, "invalid argument: after(#{kind.inspect})"
427
+ end
428
+ end
429
+
430
+
379
431
  def init(name, position, parent)
380
432
  self.position = position
381
433
  self.parent = parent
@@ -389,13 +441,16 @@ class Test::Spec::TestCase
389
441
  self.count = 0
390
442
  self.setups = []
391
443
  self.teardowns = []
444
+
445
+ self.before_all = []
446
+ self.after_all = []
392
447
  end
393
448
  end
394
449
 
395
450
  @@POSITION = 0
396
451
 
397
- def initialize(name, parent=nil)
398
- @testcase = Class.new(Test::Unit::TestCase) {
452
+ def initialize(name, parent=nil, superclass=Test::Unit::TestCase)
453
+ @testcase = Class.new(superclass) {
399
454
  include InstanceMethods
400
455
  extend ClassMethods
401
456
  }
@@ -412,6 +467,22 @@ class Test::Spec::TestCase
412
467
  end
413
468
  end
414
469
 
470
+ (Test::Spec::DisabledTestCase = Test::Spec::TestCase.dup).class_eval do
471
+ alias :test_case_initialize :initialize
472
+
473
+ def initialize(*args, &block)
474
+ test_case_initialize(*args, &block)
475
+ @testcase.instance_eval do
476
+ alias :test_case_specify :specify
477
+
478
+ def specify(specname, &block)
479
+ test_case_specify(specname) { @_result.add_disabled(specname) }
480
+ end
481
+ alias :it :specify
482
+ end
483
+ end
484
+ end
485
+
415
486
  class Test::Spec::Disabled < Test::Unit::Failure # :nodoc:
416
487
  def initialize(name)
417
488
  @name = name
@@ -430,6 +501,24 @@ class Test::Spec::Disabled < Test::Unit::Failure # :nodoc:
430
501
  end
431
502
  end
432
503
 
504
+ class Test::Spec::Empty < Test::Unit::Failure # :nodoc:
505
+ def initialize(name)
506
+ @name = name
507
+ end
508
+
509
+ def single_character_display
510
+ ""
511
+ end
512
+
513
+ def short_display
514
+ @name
515
+ end
516
+
517
+ def long_display
518
+ @name + " is empty"
519
+ end
520
+ end
521
+
433
522
 
434
523
  # Monkey-patch test/unit to run tests in an optionally specified order.
435
524
  module Test::Unit # :nodoc:
@@ -438,9 +527,11 @@ module Test::Unit # :nodoc:
438
527
  def run(result, &progress_block)
439
528
  sort!
440
529
  yield(STARTED, name)
530
+ @tests.first.before_all if @tests.first.respond_to? :before_all
441
531
  @tests.each do |test|
442
532
  test.run(result, &progress_block)
443
533
  end
534
+ @tests.last.after_all if @tests.last.respond_to? :after_all
444
535
  yield(FINISHED, name)
445
536
  end
446
537
 
@@ -465,6 +556,21 @@ module Test::Unit # :nodoc:
465
556
  end
466
557
 
467
558
 
559
+ # Hide Test::Spec interna in backtraces.
560
+ module Test::Unit::Util::BacktraceFilter # :nodoc:
561
+ TESTSPEC_PREFIX = __FILE__.gsub(/spec\.rb\Z/, '')
562
+
563
+ alias testspec_filter_backtrace filter_backtrace
564
+ def filter_backtrace(backtrace, prefix=nil)
565
+ if prefix.nil?
566
+ testspec_filter_backtrace(testspec_filter_backtrace(backtrace),
567
+ TESTSPEC_PREFIX)
568
+ else
569
+ testspec_filter_backtrace(backtrace, prefix)
570
+ end
571
+ end
572
+ end
573
+
468
574
 
469
575
  #-- Global helpers
470
576
 
@@ -482,9 +588,16 @@ class Object
482
588
  end
483
589
 
484
590
  module Kernel
485
- def context(name, &block) # :doc:
486
- (Test::Spec::CONTEXTS[name] ||= Test::Spec::TestCase.new(name)).add(&block)
591
+ def context(name, superclass=Test::Unit::TestCase, klass=Test::Spec::TestCase, &block) # :doc:
592
+ (Test::Spec::CONTEXTS[name] ||= klass.new(name, nil, superclass)).add(&block)
487
593
  end
488
594
 
489
- private :context
595
+ def xcontext(name, superclass=Test::Unit::TestCase, &block) # :doc:
596
+ context(name, superclass, Test::Spec::DisabledTestCase, &block)
597
+ end
598
+
599
+ private :context, :xcontext
600
+
601
+ alias :describe :context
602
+ alias :xdescribe :xcontext
490
603
  end
data/lib/test/spec/dox.rb CHANGED
@@ -12,6 +12,9 @@ module Test::Unit::UI # :nodoc:
12
12
  if fault.kind_of? Test::Spec::Disabled
13
13
  @disabled += 1
14
14
  output_no_nl " (disabled)"
15
+ elsif fault.kind_of? Test::Spec::Empty
16
+ @empty += 1
17
+ output_no_nl " (empty)"
15
18
  else
16
19
  @faults << fault
17
20
  word = fault.class.name[/(.*::)?(.*)/, 2].upcase
@@ -24,6 +27,7 @@ module Test::Unit::UI # :nodoc:
24
27
  @context = nil
25
28
  @contexts = []
26
29
  @disabled = 0
30
+ @empty = 0
27
31
  indent 0
28
32
  end
29
33
 
@@ -45,15 +49,24 @@ module Test::Unit::UI # :nodoc:
45
49
  disabled = ""
46
50
  end
47
51
 
48
- r = "%d specifications#{disabled} (%d requirements), %d failures" % [
49
- @result.run_count, @result.assertion_count, @result.failure_count]
52
+ if @empty > 0
53
+ empty = ", #{@empty} empty"
54
+ else
55
+ empty = ""
56
+ end
57
+
58
+ r = ("%d specifications#{disabled}#{empty} " +
59
+ "(%d requirements), %d failures") % [
60
+ @result.run_count, @result.assertion_count, @result.failure_count]
50
61
  r << ", #{@result.error_count} errors" if @result.error_count > 0
51
62
  output r
52
63
  end
53
64
 
54
65
  def test_started(name)
55
- contextname, specname = unmangle name
56
- return if contextname.nil? || specname.nil?
66
+ return if special_test? name
67
+
68
+ contextname, @specname = unmangle name
69
+ return if contextname.nil? || @specname.nil?
57
70
 
58
71
  if @context != contextname
59
72
  @context = contextname
@@ -75,10 +88,19 @@ module Test::Unit::UI # :nodoc:
75
88
  }
76
89
  end
77
90
 
78
- output_item specname
91
+ @assertions = @result.assertion_count
92
+ @prevdisabled = @disabled
93
+ output_item @specname
79
94
  end
80
95
 
81
96
  def test_finished(name)
97
+ return if special_test? name
98
+
99
+ # Did any assertion run?
100
+ if @assertions == @result.assertion_count && @prevdisabled == @disabled
101
+ add_fault Test::Spec::Empty.new(@specname)
102
+ end
103
+
82
104
  # Don't let empty contexts clutter up the output.
83
105
  nl unless name =~ /\Adefault_test\(/
84
106
  end
@@ -117,6 +139,10 @@ module Test::Unit::UI # :nodoc:
117
139
  @indent = depth
118
140
  @prefix = " " * depth
119
141
  end
142
+
143
+ def special_test?(name)
144
+ name =~ /\Atest_spec \{.*?\} (-1 BEFORE|AFTER) ALL\(/
145
+ end
120
146
  end
121
147
  end
122
148
  end
@@ -0,0 +1,8 @@
1
+ # To load it externally, without activating Test::Unit.
2
+
3
+ module Test
4
+ module Spec
5
+ VERSION = "0.4"
6
+ end
7
+ end
8
+
@@ -20,6 +20,8 @@ rescue LoadError
20
20
  else
21
21
 
22
22
  context "flexmock" do
23
+ include FlexMock::TestCase
24
+
23
25
  setup do
24
26
  @mock = FlexMock.new
25
27
  end
@@ -69,7 +71,7 @@ context "flexmock" do
69
71
  @mock.blip
70
72
  @mock.blip
71
73
  @mock.blip
72
- @mock.mock_verify
74
+ lambda { @mock.mock_verify }.should.not.raise Test::Unit::AssertionFailedError
73
75
  end
74
76
 
75
77
  specify "should raise on bad counts" do
@@ -80,12 +82,14 @@ context "flexmock" do
80
82
  end
81
83
 
82
84
  specify "should handle undetermined counts" do
83
- FlexMock.use('fs') { |m|
84
- m.mock_handle(:blip)
85
- m.blip
86
- m.blip
87
- m.blip
88
- }
85
+ lambda {
86
+ FlexMock.use('fs') { |m|
87
+ m.mock_handle(:blip)
88
+ m.blip
89
+ m.blip
90
+ m.blip
91
+ }
92
+ }.should.not.raise Test::Unit::AssertionFailedError
89
93
  end
90
94
 
91
95
  specify "should handle zero counts" do
@@ -0,0 +1,72 @@
1
+ describe "A new-style description" do
2
+ before do
3
+ @before = true
4
+ @a = 2
5
+ end
6
+
7
+ before(:each) do
8
+ @before_each = true
9
+ end
10
+
11
+ before(:all) do
12
+ $before_all = true
13
+ end
14
+
15
+ it "should run before-clauses" do
16
+ $before_all.should.be true
17
+ @before.should.be true
18
+ @before_each.should.be true
19
+ end
20
+
21
+ it "should behave like context/specify" do
22
+ (1+1).should.equal 2
23
+ end
24
+
25
+ xit "this is disabled" do
26
+ bla
27
+ end
28
+
29
+ after do
30
+ @a.should.equal 2
31
+ @a = 3
32
+ end
33
+
34
+ after(:each) do
35
+ @a.should.equal 3
36
+ end
37
+
38
+ after(:all) do
39
+ @b = 1
40
+ end
41
+
42
+ after(:all) do
43
+ @b.should.equal 1
44
+ end
45
+
46
+ $describescope = self
47
+ it "should raise on unimplement{ed,able} before/after" do
48
+ lambda {
49
+ $describescope.before(:foo) {}
50
+ }.should.raise(ArgumentError)
51
+ lambda {
52
+ $describescope.after(:foo) {}
53
+ }.should.raise(ArgumentError)
54
+
55
+ lambda {
56
+ context "foo" do
57
+ end
58
+ }.should.raise(Test::Spec::DefinitionError)
59
+ end
60
+
61
+ describe "when nested" do
62
+ it "should work" do
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "An empty description" do
68
+ end
69
+
70
+ xdescribe "An disabled description" do
71
+ it "should not be run"
72
+ end
@@ -148,6 +148,16 @@ context "test/spec" do
148
148
  lambda { lambda { raise "Error" }.should.raise(Interrupt) }.should fail
149
149
  end
150
150
 
151
+ specify "has should.raise with a block" do
152
+ lambda { should.raise { raise "Error" } }.should succeed
153
+ lambda { should.raise(RuntimeError) { raise "Error" } }.should succeed
154
+ lambda { should.not.raise { raise "Error" } }.should fail
155
+ lambda { should.not.raise(RuntimeError) { raise "Error" } }.should fail
156
+
157
+ lambda { should.raise { 1 + 1 } }.should fail
158
+ lambda { should.raise(Interrupt) { raise "Error" } }.should fail
159
+ end
160
+
151
161
  specify "should.raise should return the exception" do
152
162
  ex = lambda { raise "foo!" }.should.raise
153
163
  ex.should.be.kind_of RuntimeError
@@ -372,6 +382,12 @@ context "test/spec" do
372
382
  lambda {
373
383
  $contextscope.specify "foo"
374
384
  }.should.raise(ArgumentError)
385
+ lambda {
386
+ $contextscope.xspecify
387
+ }.should.raise(ArgumentError)
388
+ lambda {
389
+ $contextscope.xspecify "foo"
390
+ }.should.not.raise(ArgumentError) # allow empty xspecifys
375
391
  lambda {
376
392
  Kernel.send(:context, "foo")
377
393
  }.should.raise(ArgumentError)
@@ -465,10 +481,26 @@ context "test/spec" do
465
481
  # just trying
466
482
  end
467
483
 
484
+ xspecify "empty specification"
485
+
468
486
  context "more disabled" do
469
487
  xspecify "this is intentional" do
470
488
  # ...
471
489
  end
490
+
491
+ specify "an empty specification" do
492
+ # ...
493
+ end
494
+
495
+ xcontext "even more disabled" do
496
+ specify "we can cut out" do
497
+ # ...
498
+ end
499
+
500
+ specify "entire contexts, now" do
501
+ # ...
502
+ end
503
+ end
472
504
  end
473
505
  end
474
506
 
@@ -520,3 +552,21 @@ context "contexts" do
520
552
  foo.should.equal 42
521
553
  end
522
554
  end
555
+
556
+ class CustomTestUnitSubclass < Test::Unit::TestCase
557
+ def test_truth
558
+ assert true
559
+ end
560
+ end
561
+
562
+ context "contexts with subclasses", CustomTestUnitSubclass do
563
+ specify "use the supplied class as the superclass" do
564
+ self.should.be.a.kind_of CustomTestUnitSubclass
565
+ end
566
+ end
567
+
568
+ xcontext "xcontexts with subclasses", CustomTestUnitSubclass do
569
+ specify "work great!" do
570
+ self.should.be.a.kind_of CustomTestUnitSubclass
571
+ end
572
+ end
@@ -9,6 +9,7 @@ class TestTestUnit < Test::Unit::TestCase
9
9
  def test_supports_should_good_enough
10
10
  (2 + 3).should.be 5
11
11
  lambda { raise "Error" }.should.raise
12
+ assert true
12
13
  end
13
14
  end
14
15
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0.8
3
3
  specification_version: 1
4
4
  name: test-spec
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2007-01-24 00:00:00 +01:00
6
+ version: 0.4.0
7
+ date: 2007-06-29 00:00:00 +02:00
8
8
  summary: test/spec layers an RSpec-inspired interface on top of Test::Unit, so you can mix TDD and BDD (Behavior-Driven Development). test/spec is a clean-room implementation that maps most kinds of Test::Unit assertions to a `should'-like syntax.
9
9
  require_paths:
10
10
  - lib
@@ -35,6 +35,7 @@ files:
35
35
  - lib/test/spec/dox.rb
36
36
  - lib/test/spec/rdox.rb
37
37
  - lib/test/spec/should-output.rb
38
+ - lib/test/spec/version.rb
38
39
  - lib/test/spec.rb
39
40
  - Rakefile
40
41
  - README
@@ -43,6 +44,7 @@ files:
43
44
  - test/spec_flexmock.rb
44
45
  - test/spec_mocha.rb
45
46
  - test/spec_nestedcontexts.rb
47
+ - test/spec_new_style.rb
46
48
  - test/spec_should-output.rb
47
49
  - test/spec_testspec.rb
48
50
  - test/spec_testspec_order.rb
@@ -54,6 +56,7 @@ test_files:
54
56
  - test/spec_flexmock.rb
55
57
  - test/spec_mocha.rb
56
58
  - test/spec_nestedcontexts.rb
59
+ - test/spec_new_style.rb
57
60
  - test/spec_should-output.rb
58
61
  - test/spec_testspec.rb
59
62
  - test/spec_testspec_order.rb
@@ -67,22 +70,5 @@ extensions: []
67
70
 
68
71
  requirements: []
69
72
 
70
- dependencies:
71
- - !ruby/object:Gem::Dependency
72
- name: flexmock
73
- version_requirement:
74
- version_requirements: !ruby/object:Gem::Version::Requirement
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: 0.4.1
79
- version:
80
- - !ruby/object:Gem::Dependency
81
- name: mocha
82
- version_requirement:
83
- version_requirements: !ruby/object:Gem::Version::Requirement
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- version: 0.3.2
88
- version:
73
+ dependencies: []
74
+