test-spec 0.4.0 → 0.9.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/README CHANGED
@@ -1,6 +1,6 @@
1
1
  = test/spec, a BDD interface for Test::Unit
2
2
 
3
- Copyright (C) 2006, 2007 Christian Neukirchen <mailto:chneukirchen@gmail.com>
3
+ Copyright (C) 2006, 2007, 2008 Christian Neukirchen <mailto:chneukirchen@gmail.com>
4
4
 
5
5
 
6
6
  == What is test/spec?
@@ -58,8 +58,10 @@ monkey-patching Test::Unit::TestSuite to order the test cases before
58
58
  running them. (This should not do any harm, but if you know a way
59
59
  around it, please tell me.)
60
60
 
61
- test/spec adds three global methods, Object#should, Kernel.context,
62
- and Kernel.describe.
61
+ test/spec adds seven global methods, Object#should, Kernel.context,
62
+ Kernel.xcontext, Kernel.shared_context, Kernel.describe,
63
+ Kernel.xdescribe, and Kernel.describe_shared. The Kernel methods are
64
+ private.
63
65
 
64
66
  You can use <tt>assert_*</tt> freely in specify-blocks; Object#should
65
67
  works in plain Test::Unit test cases, too, but they will not be counted.
@@ -228,6 +230,15 @@ visible to other specifications. They are e.g. useful for setting up
228
230
  database connections or starting servers.
229
231
 
230
232
 
233
+ == Shared contexts
234
+
235
+ Since version 0.9, you can define shared contexts in test/spec using
236
+ shared_context/describe_shared. These contexts are not executed on
237
+ their own, but can be included with it_should_behave_like/behaves_like
238
+ in other contexts. You can use shared contexts to structure suites
239
+ with many recurring specifications.
240
+
241
+
231
242
  == specrb
232
243
 
233
244
  Since version 0.2, test/spec features a standalone test runner called
@@ -310,6 +321,12 @@ at my site:
310
321
  * Make SpecDox and RDox count empty specifications.
311
322
  * Allow Kernel#context to take a superclass.
312
323
 
324
+ * July 2nd, 2008: Fifth public release 0.9.
325
+ * Allow should.<predicate>? as well as should.<predicate>.
326
+ * Add shared contexts.
327
+ * Nested contexts now run the
328
+ setups/teardowns/before(:all)/after(:all) of their parents.
329
+
313
330
 
314
331
  == Contact
315
332
 
@@ -325,6 +342,7 @@ http://chneukirchen.org/repos/testspec
325
342
  * Eero Saynatkari for writing <tt>should.output</tt>.
326
343
  * Tuxie for writing test/spec on Rails.
327
344
  * Brian Donovan for allowing alternative superclasses.
345
+ * Xavier Shay for implementing nested setups/teardowns.
328
346
  * Chris Wanstrath for <tt>should.raise</tt> with a block and <tt>xcontext</tt>.
329
347
  * Jean-Michel Garnier for packaging the first gem.
330
348
  * Mikko Lehtonen, Jan Wikholm, Matt Mower and Michael Fellinger for
@@ -338,7 +356,7 @@ http://chneukirchen.org/repos/testspec
338
356
 
339
357
  == Copying
340
358
 
341
- Copyright (C) 2006, 2007 Christian Neukirchen <http://purl.org/net/chneukirchen>
359
+ Copyright (C) 2006, 2007, 2008 Christian Neukirchen <http://purl.org/net/chneukirchen>
342
360
 
343
361
  test/spec is licensed under the same terms as Ruby itself.
344
362
 
data/ROADMAP CHANGED
@@ -1 +1 @@
1
- Version 1.0 (February 2006):: first stable release.
1
+ Version 1.0 (2008):: everything-done release.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ desc "Run all the tests"
7
7
  task :default => [:test]
8
8
 
9
9
  desc "Do predistribution stuff"
10
- task :predist => [:chmod, :changelog, :rdoc, :distmanifest]
10
+ task :predist => [:chmod, :changelog, :rdoc]
11
11
 
12
12
 
13
13
  desc "Make an archive as .tar.gz"
@@ -45,6 +45,10 @@ def get_darcs_tree_version
45
45
  tag + "." + count.to_s
46
46
  end
47
47
 
48
+ def manifest
49
+ `darcs query manifest 2>/dev/null`.split("\n").map { |f| f.gsub(/\A\.\//, '') }
50
+ end
51
+
48
52
 
49
53
  desc "Make binaries executable"
50
54
  task :chmod do
@@ -62,66 +66,57 @@ task "SPECS" do
62
66
  ruby "bin/specrb -Ilib:test -a --rdox >SPECS"
63
67
  end
64
68
 
69
+ desc "Run all the tests"
70
+ task :test => :chmod do
71
+ ruby "bin/specrb -Ilib:test -w #{ENV['TEST'] || '-a'} #{ENV['TESTOPTS']}"
72
+ end
65
73
 
66
- begin
67
- # To generate the gem, run "rake package"
68
74
 
69
- $" << "sources" if defined? FromSrc
75
+ begin
70
76
  require 'rubygems'
71
77
 
72
78
  require 'rake'
73
79
  require 'rake/clean'
74
80
  require 'rake/packagetask'
75
81
  require 'rake/gempackagetask'
76
- require 'rake/contrib/rubyforgepublisher'
77
82
  require 'fileutils'
78
- require 'hoe'
79
83
  rescue LoadError
80
84
  # 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
85
  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
86
+ spec = Gem::Specification.new do |s|
87
+ s.name = "test-spec"
88
+ s.version = get_darcs_tree_version
89
+ s.platform = Gem::Platform::RUBY
90
+ s.summary = "a Behaviour Driven Development interface for Test::Unit"
91
+ s.description = <<-EOF
102
92
  test/spec layers an RSpec-inspired interface on top of Test::Unit, so
103
93
  you can mix TDD and BDD (Behavior-Driven Development).
104
94
 
105
95
  test/spec is a clean-room implementation that maps most kinds of
106
96
  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
97
+ EOF
98
+
99
+ s.files = manifest + %w(SPECS)
100
+ s.bindir = 'bin'
101
+ s.executables << 'specrb'
102
+ s.require_path = 'lib'
103
+ s.has_rdoc = true
104
+ s.extra_rdoc_files = ['README', 'SPECS', 'ROADMAP']
105
+ s.test_files = Dir['test/{test,spec}_*.rb']
106
+
107
+ s.author = 'Christian Neukirchen'
108
+ s.email = 'chneukirchen@gmail.com'
109
+ s.homepage = "http://test-spec.rubyforge.org"
110
+ s.rubyforge_project = 'test-spec'
111
+ end
112
+
113
+ task :package => [:dist]
114
+
115
+ Rake::GemPackageTask.new(spec) do |p|
116
+ p.gem_spec = spec
117
+ p.need_tar = false
118
+ p.need_zip = false
119
+ end
125
120
  end
126
121
 
127
122
 
@@ -137,20 +132,6 @@ end
137
132
  task :rdoc => "SPECS"
138
133
 
139
134
 
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
135
  begin
155
136
  require 'rcov/rcovtask'
156
137
 
data/SPECS ADDED
@@ -0,0 +1,161 @@
1
+
2
+ == TestUnit
3
+ * still works on its own
4
+ * supports should good enough
5
+ * works inside test/spec
6
+
7
+ == CustomTestUnitSubclass
8
+ * truth
9
+
10
+ == test/spec
11
+ * has should.satisfy
12
+ * has should.equal
13
+ * has should.raise
14
+ * has should.raise with a block
15
+ * should.raise should return the exception
16
+ * has should.be.an.instance_of
17
+ * has should.be.nil
18
+ * has should.include
19
+ * has should.be.a.kind_of
20
+ * has should.match
21
+ * has should.be
22
+ * has should.not.raise
23
+ * has should.not.satisfy
24
+ * has should.not.be
25
+ * has should.not.equal
26
+ * has should.not.match
27
+ * has should.throw
28
+ * has should.not.throw
29
+ * has should.respond_to
30
+ * has should.be_close
31
+ * multiple negation works
32
+ * has should.<predicate>
33
+ * has should.<predicate>?
34
+ * has should <operator> (>, >=, <, <=, ===)
35
+ * is robust against careless users
36
+ * should detect warnings
37
+ * should message/blame faults
38
+ * should allow for custom shoulds
39
+ * disabled specification (disabled)
40
+ * empty specification (disabled)
41
+ === more disabled
42
+ * this is intentional (disabled)
43
+ * an empty specification (empty)
44
+ ==== even more disabled
45
+ * we can cut out (disabled)
46
+ * entire contexts, now (disabled)
47
+
48
+ == setup/teardown
49
+ * run in the right order
50
+
51
+ == before all
52
+ * runs parent before all
53
+
54
+ == nested teardown
55
+ === nested
56
+ * should call local teardown then parent teardown
57
+
58
+ == before all
59
+ === nested
60
+ * should call parent then local
61
+
62
+ == after all
63
+ === after nested
64
+ * should call local then parent
65
+
66
+ == contexts
67
+ * are defined in class scope
68
+ * can include modules
69
+
70
+ == contexts with subclasses
71
+ * use the supplied class as the superclass
72
+ * truth
73
+
74
+ == xcontexts with subclasses
75
+ * work great! (disabled)
76
+ * truth
77
+
78
+ == Shared contexts
79
+ * can be included several times
80
+ * can include other shared contexts
81
+ * can be included several times
82
+ * can include other shared contexts
83
+ * can be nested
84
+ * can access data
85
+ * should raise when the context cannot be found
86
+
87
+ == SpecDox
88
+ * can unmangle Test::Unit names correctly
89
+ * can unmangle Test::Spec names correctly
90
+ * has sensible fallbacks
91
+
92
+ == flexmock
93
+ * should receive and return
94
+ * should receive without a block
95
+ * should receive and return with a block
96
+ * should have a return value
97
+ * should handle missing methods
98
+ * should ignore missing methods
99
+ * should count correctly
100
+ * should raise on bad counts
101
+ * should handle undetermined counts
102
+ * should handle zero counts
103
+ * should have file IO with use
104
+ * should have use
105
+ * should handle failures during use
106
+ * should deal with sequential values
107
+ * respond_to? should return false for non handled methods
108
+ * respond_to? should return true for explicit methods
109
+ * respond_to? should return true for missing_methods when should_ignore_missing
110
+ * should raise error on unknown method proc
111
+ * should return callable proc on method
112
+ * should return do nothing proc for missing methods
113
+ * works with test/spec
114
+
115
+ == mocha
116
+ * works with test/spec
117
+ * works with test/spec and Enterprise example
118
+
119
+ == stubba
120
+ * works with test/spec and instance method stubbing
121
+ * works with test/spec and class method stubbing
122
+ * works with test/spec and global instance method stubbing
123
+
124
+ == Outer context
125
+ === Inner context
126
+ * is nested (empty)
127
+ * has multiple empty specifications (empty)
128
+ === Second Inner context
129
+ * is indented properly (empty)
130
+ * still runs in order of definition (empty)
131
+ ==== Inmost context
132
+ * works too! (empty)
133
+ * whoo! (empty)
134
+
135
+ == A new-style description
136
+ * should run before-clauses
137
+ * should behave like context/specify
138
+ * this is disabled (disabled)
139
+ * should raise on unimplement{ed,able} before/after
140
+ * should work as well with shared descriptions
141
+ === when nested
142
+ * should work
143
+
144
+ == An disabled description
145
+ * should not be run (disabled)
146
+
147
+ == should.output
148
+ * works for print
149
+ * works for puts
150
+ * works with readline
151
+
152
+ == Context First
153
+ * runs before Second
154
+
155
+ == Context Second
156
+ * runs before Last
157
+
158
+ == Context Last
159
+ * runs last
160
+
161
+ 104 specifications, 8 disabled, 7 empty (636 requirements), 0 failures
data/TODO CHANGED
@@ -1,3 +1,2 @@
1
1
  - see ROADMAP
2
2
  - better handling of .should outside of specify(?)
3
- - shared behaviors?
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # test/spec -- a BDD interface for Test::Unit
3
3
  #
4
- # Copyright (C) 2006, 2007 Christian Neukirchen <mailto:chneukirchen@gmail.com>
4
+ # Copyright (C) 2006, 2007, 2008 Christian Neukirchen <mailto:chneukirchen@gmail.com>
5
5
  #
6
6
  # This work is licensed under the same terms as Ruby itself.
7
7
  #
@@ -27,6 +27,7 @@ module Test::Spec
27
27
  require 'test/spec/version'
28
28
 
29
29
  CONTEXTS = {} # :nodoc:
30
+ SHARED_CONTEXTS = Hash.new { |h,k| h[k] = [] } # :nodoc:
30
31
 
31
32
  class DefinitionError < StandardError
32
33
  end
@@ -186,7 +187,12 @@ module Test::Spec
186
187
  assert @object.__send__("#{name}?", *args),
187
188
  "#{name}? expected to be true. #{@message}"
188
189
  else
189
- super
190
+ if @object.respond_to?(name)
191
+ assert @object.__send__(name, *args),
192
+ "#{name} expected to be true. #{@message}"
193
+ else
194
+ super
195
+ end
190
196
  end
191
197
  end
192
198
  end
@@ -282,7 +288,13 @@ module Test::Spec
282
288
  not @object.__send__("#{name}?", *args)
283
289
  }
284
290
  else
285
- super
291
+ if @object.respond_to?(name)
292
+ assert_block("#{name} expected to be false. #{@message}") {
293
+ not @object.__send__("#{name}", *args)
294
+ }
295
+ else
296
+ super
297
+ end
286
298
  end
287
299
  end
288
300
 
@@ -319,20 +331,20 @@ class Test::Spec::TestCase
319
331
  def setup # :nodoc:
320
332
  $TEST_SPEC_TESTCASE = self
321
333
  super
322
- self.class.setups.each { |s| instance_eval(&s) }
334
+ call_methods_including_parents(:setups)
323
335
  end
324
336
 
325
337
  def teardown # :nodoc:
326
338
  super
327
- self.class.teardowns.each { |t| instance_eval(&t) }
339
+ call_methods_including_parents(:teardowns, :reverse)
328
340
  end
329
341
 
330
342
  def before_all
331
- self.class.before_all.each { |t| instance_eval(&t) }
343
+ call_methods_including_parents(:before_all)
332
344
  end
333
345
 
334
346
  def after_all
335
- self.class.after_all.each { |t| instance_eval(&t) }
347
+ call_methods_including_parents(:after_all, :reverse)
336
348
  end
337
349
 
338
350
  def initialize(name)
@@ -353,6 +365,20 @@ class Test::Spec::TestCase
353
365
  end
354
366
 
355
367
  alias :describe :context
368
+
369
+ private
370
+
371
+ def call_methods_including_parents(method, reverse=false, klass=self.class)
372
+ return unless klass
373
+
374
+ if reverse
375
+ klass.send(method).each { |s| instance_eval(&s) }
376
+ call_methods_including_parents(method, reverse, klass.parent)
377
+ else
378
+ call_methods_including_parents(method, reverse, klass.parent)
379
+ klass.send(method).each { |s| instance_eval(&s) }
380
+ end
381
+ end
356
382
  end
357
383
 
358
384
  module ClassMethods
@@ -399,9 +425,29 @@ class Test::Spec::TestCase
399
425
  teardowns << block
400
426
  end
401
427
 
428
+ def shared_context(name, &block)
429
+ Test::Spec::SHARED_CONTEXTS[self.name + "\t" + name] << block
430
+ end
431
+
432
+ def behaves_like(shared_context)
433
+ if Test::Spec::SHARED_CONTEXTS.include?(shared_context)
434
+ Test::Spec::SHARED_CONTEXTS[shared_context].each { |block|
435
+ instance_eval(&block)
436
+ }
437
+ elsif Test::Spec::SHARED_CONTEXTS.include?(self.name + "\t" + shared_context)
438
+ Test::Spec::SHARED_CONTEXTS[self.name + "\t" + shared_context].each { |block|
439
+ instance_eval(&block)
440
+ }
441
+ else
442
+ raise NameError, "Shared context #{shared_context} not found."
443
+ end
444
+ end
445
+ alias :it_should_behave_like :behaves_like
446
+
402
447
  # new-style (RSpec 1.0+):
403
448
 
404
449
  alias :describe :context
450
+ alias :describe_shared :shared_context
405
451
  alias :it :specify
406
452
  alias :xit :xspecify
407
453
 
@@ -560,7 +606,12 @@ end
560
606
  module Test::Unit::Util::BacktraceFilter # :nodoc:
561
607
  TESTSPEC_PREFIX = __FILE__.gsub(/spec\.rb\Z/, '')
562
608
 
563
- alias testspec_filter_backtrace filter_backtrace
609
+ # Vendor plugins like to be loaded several times, don't recurse
610
+ # infinitely then.
611
+ unless method_defined? "testspec_filter_backtrace"
612
+ alias :testspec_filter_backtrace :filter_backtrace
613
+ end
614
+
564
615
  def filter_backtrace(backtrace, prefix=nil)
565
616
  if prefix.nil?
566
617
  testspec_filter_backtrace(testspec_filter_backtrace(backtrace),
@@ -596,8 +647,14 @@ module Kernel
596
647
  context(name, superclass, Test::Spec::DisabledTestCase, &block)
597
648
  end
598
649
 
599
- private :context, :xcontext
650
+ def shared_context(name, &block)
651
+ Test::Spec::SHARED_CONTEXTS[name] << block
652
+ end
600
653
 
601
654
  alias :describe :context
602
655
  alias :xdescribe :xcontext
656
+ alias :describe_shared :shared_context
657
+
658
+ private :context, :xcontext, :shared_context
659
+ private :describe, :xdescribe, :describe_shared
603
660
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Test
4
4
  module Spec
5
- VERSION = "0.4"
5
+ VERSION = "0.9"
6
6
  end
7
7
  end
8
8
 
@@ -26,29 +26,29 @@ context "flexmock" do
26
26
  @mock = FlexMock.new
27
27
  end
28
28
 
29
- specify "should handle" do
29
+ specify "should receive and return" do
30
30
  args = nil
31
- @mock.mock_handle(:hi) { |a, b| args = [a,b] }
31
+ @mock.should_receive(:hi).and_return { |a, b| args = [a,b] }
32
32
  @mock.hi(1,2)
33
33
  args.should.equal [1,2]
34
34
  end
35
35
 
36
- specify "should handle without a block" do
36
+ specify "should receive without a block" do
37
37
  lambda {
38
- @mock.mock_handle(:blip)
38
+ @mock.should_receive(:blip)
39
39
  @mock.blip
40
40
  }.should.not.raise
41
41
  end
42
42
 
43
- specify "should handle with a block" do
43
+ specify "should receive and return with a block" do
44
44
  called = false
45
- @mock.mock_handle(:blip) { |block| block.call }
45
+ @mock.should_receive(:blip).and_return { |block| block.call }
46
46
  @mock.blip { called = true }
47
47
  called.should.be true
48
48
  end
49
49
 
50
50
  specify "should have a return value" do
51
- @mock.mock_handle(:blip) { 10 }
51
+ @mock.should_receive(:blip).and_return { 10 }
52
52
  @mock.blip.should.equal 10
53
53
  end
54
54
 
@@ -61,30 +61,30 @@ context "flexmock" do
61
61
 
62
62
  specify "should ignore missing methods" do
63
63
  lambda {
64
- @mock.mock_ignore_missing
64
+ @mock.should_ignore_missing
65
65
  @mock.blip
66
66
  }.should.not.raise
67
67
  end
68
68
 
69
69
  specify "should count correctly" do
70
- @mock.mock_handle(:blip, 3)
70
+ @mock.should_receive(:blip).times(3)
71
71
  @mock.blip
72
72
  @mock.blip
73
73
  @mock.blip
74
- lambda { @mock.mock_verify }.should.not.raise Test::Unit::AssertionFailedError
74
+ lambda { @mock.flexmock_verify }.should.not.raise Test::Unit::AssertionFailedError
75
75
  end
76
76
 
77
77
  specify "should raise on bad counts" do
78
- @mock.mock_handle(:blip, 3)
78
+ @mock.should_receive(:blip).times(3)
79
79
  @mock.blip
80
80
  @mock.blip
81
- lambda { @mock.mock_verify }.should.raise Test::Unit::AssertionFailedError
81
+ lambda { @mock.flexmock_verify }.should.raise Test::Unit::AssertionFailedError
82
82
  end
83
83
 
84
84
  specify "should handle undetermined counts" do
85
85
  lambda {
86
86
  FlexMock.use('fs') { |m|
87
- m.mock_handle(:blip)
87
+ m.should_receive(:blip)
88
88
  m.blip
89
89
  m.blip
90
90
  m.blip
@@ -95,7 +95,7 @@ context "flexmock" do
95
95
  specify "should handle zero counts" do
96
96
  lambda {
97
97
  FlexMock.use { |m|
98
- m.mock_handle(:blip, 0)
98
+ m.should_receive(:blip).never
99
99
  m.blip
100
100
  }
101
101
  }.should.raise Test::Unit::AssertionFailedError
@@ -104,7 +104,7 @@ context "flexmock" do
104
104
  specify "should have file IO with use" do
105
105
  file = FlexMock.use do |m|
106
106
  filedata = ["line 1", "line 2"]
107
- m.mock_handle(:gets, 3) { filedata.shift }
107
+ m.should_receive(:gets).times(3).and_return { filedata.shift }
108
108
  count_lines(m).should.equal 2
109
109
  end
110
110
  end
@@ -120,7 +120,7 @@ context "flexmock" do
120
120
  specify "should have use" do
121
121
  lambda {
122
122
  FlexMock.use do |m|
123
- m.mock_handle(:blip, 2)
123
+ m.should_receive(:blip).times(2)
124
124
  m.blip
125
125
  end
126
126
  }.should.raise Test::Unit::AssertionFailedError
@@ -129,7 +129,7 @@ context "flexmock" do
129
129
  specify "should handle failures during use" do
130
130
  ex = lambda {
131
131
  FlexMock.use do |m|
132
- m.mock_handle(:blip, 2)
132
+ m.should_receive(:blip).times(2)
133
133
  xyz
134
134
  end
135
135
  }.should.raise NameError
@@ -138,7 +138,7 @@ context "flexmock" do
138
138
 
139
139
  specify "should deal with sequential values" do
140
140
  values = [1,4,9,16]
141
- @mock.mock_handle(:get) { values.shift }
141
+ @mock.should_receive(:get).and_return { values.shift }
142
142
  @mock.get.should.equal 1
143
143
  @mock.get.should.equal 4
144
144
  @mock.get.should.equal 9
@@ -150,14 +150,9 @@ context "flexmock" do
150
150
  end
151
151
 
152
152
  specify "respond_to? should return true for explicit methods" do
153
- @mock.mock_handle(:xyz)
153
+ @mock.should_receive(:xyz)
154
154
  @mock.should.respond_to :xyz
155
155
  end
156
-
157
- specify "respond_to? should return true when ignoring_missing" do
158
- @mock.mock_ignore_missing
159
- @mock.should.respond_to :yada
160
- end
161
156
 
162
157
  specify "respond_to? should return true for missing_methods when should_ignore_missing" do
163
158
  @mock.should_ignore_missing
@@ -172,7 +167,7 @@ context "flexmock" do
172
167
 
173
168
  specify "should return callable proc on method" do
174
169
  got_it = false
175
- @mock.mock_handle(:xyzzy) { got_it = true }
170
+ @mock.should_receive(:xyzzy).and_return { got_it = true }
176
171
  method_proc = @mock.method(:xyzzy)
177
172
  method_proc.should.not.be.nil
178
173
  method_proc.call
@@ -180,7 +175,7 @@ context "flexmock" do
180
175
  end
181
176
 
182
177
  specify "should return do nothing proc for missing methods" do
183
- @mock.mock_ignore_missing
178
+ @mock.should_ignore_missing
184
179
  method_proc = @mock.method(:plugh)
185
180
  method_proc.should.not.be.nil
186
181
  lambda { method_proc.call }.should.not.raise
@@ -8,8 +8,6 @@
8
8
 
9
9
  require 'test/spec'
10
10
 
11
- $: << "/home/chris/src/mocha-0.3.2/lib"
12
-
13
11
  begin
14
12
  require 'mocha'
15
13
  rescue LoadError
@@ -46,18 +44,6 @@ context "mocha" do
46
44
  end
47
45
  end
48
46
 
49
- end # if not rescue LoadError
50
-
51
-
52
- begin
53
- require 'stubba'
54
- rescue LoadError
55
- context "stubba" do
56
- specify "can not be found. BAIL OUT!" do
57
- end
58
- end
59
- else
60
-
61
47
  class Order
62
48
  attr_accessor :shipped_on
63
49
 
@@ -1,3 +1,9 @@
1
+ describe_shared "A new-style shared description" do
2
+ it "should work as well with shared descriptions" do
3
+ true.should.be true
4
+ end
5
+ end
6
+
1
7
  describe "A new-style description" do
2
8
  before do
3
9
  @before = true
@@ -62,6 +68,8 @@ describe "A new-style description" do
62
68
  it "should work" do
63
69
  end
64
70
  end
71
+
72
+ behaves_like "A new-style shared description"
65
73
  end
66
74
 
67
75
  describe "An empty description" do
@@ -352,6 +352,20 @@ context "test/spec" do
352
352
  lambda { nil.should.not.bla }.should.raise(NoMethodError)
353
353
  end
354
354
 
355
+ specify "has should.<predicate>?" do
356
+ lambda { [].should.be.empty? }.should succeed
357
+ lambda { [1,2,3].should.not.be.empty? }.should succeed
358
+
359
+ lambda { [].should.not.be.empty? }.should fail
360
+ lambda { [1,2,3].should.be.empty? }.should fail
361
+
362
+ lambda { {1=>2, 3=>4}.should.has_key? 1 }.should succeed
363
+ lambda { {1=>2, 3=>4}.should.not.has_key? 2 }.should succeed
364
+
365
+ lambda { nil.should.bla? }.should.raise(NoMethodError)
366
+ lambda { nil.should.not.bla? }.should.raise(NoMethodError)
367
+ end
368
+
355
369
  specify "has should <operator> (>, >=, <, <=, ===)" do
356
370
  lambda { 2.should.be > 1 }.should succeed
357
371
  lambda { 1.should.be > 2 }.should fail
@@ -529,6 +543,73 @@ context "setup/teardown" do
529
543
  end
530
544
  end
531
545
 
546
+ context "before all" do
547
+ before(:all) { @a = 1 }
548
+
549
+ specify "runs parent before all" do
550
+ @a.should == 1
551
+ end
552
+ end
553
+
554
+ context "nested teardown" do
555
+ context "nested" do
556
+ specify "should call local teardown then parent teardown" do
557
+ @a = 3
558
+ end
559
+
560
+ teardown do
561
+ @a = 2
562
+ end
563
+ end
564
+
565
+ teardown do
566
+ @a.should.equal 2
567
+ @a = 1
568
+ end
569
+
570
+ after(:all) do
571
+ @a.should.equal 1
572
+ end
573
+ end
574
+
575
+ context "before all" do
576
+ context "nested" do
577
+ before(:all) do
578
+ @a = 2
579
+ end
580
+
581
+ specify "should call parent then local" do
582
+ @a.should.equal 2
583
+ @b.should.equal 2
584
+ end
585
+ end
586
+
587
+ before(:all) do
588
+ @a = 1
589
+ @b = 2
590
+ end
591
+ end
592
+
593
+ context "after all" do
594
+ context "after nested" do
595
+ after(:all) do
596
+ @a = 2
597
+ end
598
+
599
+ specify "should call local then parent" do
600
+ self.after_all
601
+ @a.should.equal 1
602
+ @b.should.equal 2
603
+ end
604
+ end
605
+
606
+ after(:all) do
607
+ @b = @a
608
+ @a = 1
609
+ end
610
+ end
611
+
612
+
532
613
  module ContextHelper
533
614
  def foo
534
615
  42
@@ -570,3 +651,49 @@ xcontext "xcontexts with subclasses", CustomTestUnitSubclass do
570
651
  self.should.be.a.kind_of CustomTestUnitSubclass
571
652
  end
572
653
  end
654
+
655
+ shared_context "a shared context" do
656
+ specify "can be included several times" do
657
+ true.should.be true
658
+ end
659
+
660
+ behaves_like "yet another shared context"
661
+ end
662
+
663
+ shared_context "another shared context" do
664
+ specify "can access data" do
665
+ @answer.should.be 42
666
+ end
667
+ end
668
+
669
+ shared_context "yet another shared context" do
670
+ specify "can include other shared contexts" do
671
+ true.should.be true
672
+ end
673
+ end
674
+
675
+ context "Shared contexts" do
676
+ shared_context "a nested context" do
677
+ specify "can be nested" do
678
+ true.should.be true
679
+ end
680
+ end
681
+
682
+ setup do
683
+ @answer = 42
684
+ end
685
+
686
+ behaves_like "a shared context"
687
+ it_should_behave_like "a shared context"
688
+
689
+ behaves_like "a nested context"
690
+
691
+ behaves_like "another shared context"
692
+
693
+ ctx = self
694
+ specify "should raise when the context cannot be found" do
695
+ should.raise(NameError) {
696
+ ctx.behaves_like "no such context"
697
+ }
698
+ end
699
+ end
metadata CHANGED
@@ -1,33 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0.8
3
- specification_version: 1
4
2
  name: test-spec
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.4.0
7
- date: 2007-06-29 00:00:00 +02:00
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
- require_paths:
10
- - lib
11
- email: chneukirchen@gmail.com
12
- homepage: http://test-spec.rubyforge.org
13
- rubyforge_project: test-spec
14
- description: a Behaviour Driven Development interface for Test::Unit
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.9.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Christian Neukirchen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-02 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: 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.
17
+ email: chneukirchen@gmail.com
18
+ executables:
19
+ - specrb
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - SPECS
25
+ - ROADMAP
31
26
  files:
32
27
  - bin/specrb
33
28
  - examples/stack.rb
@@ -50,6 +45,33 @@ files:
50
45
  - test/spec_testspec_order.rb
51
46
  - test/test_testunit.rb
52
47
  - TODO
48
+ - SPECS
49
+ has_rdoc: true
50
+ homepage: http://test-spec.rubyforge.org
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: test-spec
71
+ rubygems_version: 1.0.1
72
+ signing_key:
73
+ specification_version: 2
74
+ summary: a Behaviour Driven Development interface for Test::Unit
53
75
  test_files:
54
76
  - test/test_testunit.rb
55
77
  - test/spec_dox.rb
@@ -60,15 +82,3 @@ test_files:
60
82
  - test/spec_should-output.rb
61
83
  - test/spec_testspec.rb
62
84
  - test/spec_testspec_order.rb
63
- rdoc_options: []
64
-
65
- extra_rdoc_files: []
66
-
67
- executables:
68
- - specrb
69
- extensions: []
70
-
71
- requirements: []
72
-
73
- dependencies: []
74
-