rspec 0.9.2 → 0.9.3

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/CHANGES CHANGED
@@ -1,5 +1,14 @@
1
1
  = RSpec Changelog
2
2
 
3
+ == Version 0.9.3
4
+ This is a bugfix release.
5
+
6
+ * Fixed [#10594] Failing Custom Matcher show NAME NOT GENERATED description
7
+ * describe(SomeType, "#message") will not add a space: "SomeType#message" (likewise for '.')
8
+ * describe(SomeType, "message") will have a decription with a space: "SomeType message"
9
+ * Applied [#10566] prepend_before and prepend_after callbacks
10
+ * Applied [#10567] Call setup and teardown using before and after callbacks
11
+
3
12
  == Version 0.9.2
4
13
  This is a quick maintenance release.
5
14
 
@@ -8,6 +17,7 @@ This is a quick maintenance release.
8
17
  * Added a spec:translate Rake task to make 0.9 translation easier with Spec:Rails
9
18
  * Better translation of should_redirect_to
10
19
  * Fixed --colour support for Windows. This is a regression that was introduced in 0.9.1
20
+ * Applied [#10460] Make SpecRunner easier to instantiate without using commandline args
11
21
 
12
22
  == Version 0.9.1
13
23
 
@@ -124,6 +134,7 @@ See Spec::DSL::Behaviour for more on predicate_matchers
124
134
  * Updated sample app specs to 0.9 syntax
125
135
  * Updated generated specs to 0.9 syntax
126
136
  * Applied [#8994] trunk: generated names for be_ specs (Multiple patches from Yurii Rashkovskii)
137
+ * Applied [#9983]: Allow before and after to be called in BehaviourEval. This is useful for shared examples.
127
138
 
128
139
  == Version 0.8.2
129
140
 
@@ -99,6 +99,6 @@
99
99
  # * RSpec should be able to access TestCase methods
100
100
  # * RSpec should be able to accept included modules
101
101
 
102
- Finished in 0.045762 seconds
102
+ Finished in 0.030655 seconds
103
103
 
104
104
  74 examples, 0 failures
@@ -38,6 +38,8 @@ describe "RSpec should integrate with Test::Unit::TestCase" do
38
38
 
39
39
  fixtures :some_table
40
40
 
41
+ prepend_before(:each) {setup}
42
+
41
43
  before(:each) do
42
44
  @rspec_setup_called = true
43
45
  end
@@ -1,41 +1,57 @@
1
1
  module Spec
2
2
  module DSL
3
3
  module BehaviourCallbacks
4
- def before(scope=:each, &block)
4
+ def prepend_before(scope=:each, &block)
5
+ case scope
6
+ when :each; before_each_parts.unshift(block)
7
+ when :all; before_all_parts.unshift(block)
8
+ end
9
+ end
10
+ def append_before(scope=:each, &block)
5
11
  case scope
6
12
  when :each; before_each_parts << block
7
13
  when :all; before_all_parts << block
8
14
  end
9
15
  end
16
+ alias_method :before, :append_before
10
17
 
11
- def after(scope=:each, &block)
18
+ def prepend_after(scope=:each, &block)
12
19
  case scope
13
20
  when :each; after_each_parts.unshift(block)
14
21
  when :all; after_all_parts.unshift(block)
15
22
  end
16
23
  end
24
+ alias_method :after, :prepend_after
25
+ def append_after(scope=:each, &block)
26
+ case scope
27
+ when :each; after_each_parts << block
28
+ when :all; after_all_parts << block
29
+ end
30
+ end
17
31
 
32
+ # Deprecated. Use before(:each)
18
33
  def setup(&block)
19
34
  before(:each, &block)
20
35
  end
21
36
 
37
+ # Deprecated. Use after(:each)
22
38
  def teardown(&block)
23
39
  after(:each, &block)
24
40
  end
25
41
 
26
- def before_all_parts
42
+ def before_all_parts # :nodoc:
27
43
  @before_all_parts ||= []
28
44
  end
29
45
 
30
- def after_all_parts
46
+ def after_all_parts # :nodoc:
31
47
  @after_all_parts ||= []
32
48
  end
33
49
 
34
- def before_each_parts
50
+ def before_each_parts # :nodoc:
35
51
  @before_each_parts ||= []
36
52
  end
37
53
 
38
- def after_each_parts
54
+ def after_each_parts # :nodoc:
39
55
  @after_each_parts ||= []
40
56
  end
41
57
  end
@@ -111,7 +111,6 @@ module Spec
111
111
 
112
112
  def before_each_proc(&error_handler)
113
113
  parts = []
114
- add_superclass_method(parts, 'setup')
115
114
  parts.push(*Behaviour.before_each_parts)
116
115
  parts.push(*before_each_parts)
117
116
  CompositeProcBuilder.new(parts).proc(&error_handler)
@@ -120,7 +119,6 @@ module Spec
120
119
  def after_each_proc(&error_handler)
121
120
  parts = []
122
121
  parts.push(*after_each_parts)
123
- add_superclass_method(parts, 'teardown')
124
122
  parts.push(*Behaviour.after_each_parts)
125
123
  CompositeProcBuilder.new(parts).proc(&error_handler)
126
124
  end
@@ -137,6 +135,8 @@ module Spec
137
135
 
138
136
  def derive_execution_context_class_from_behaviour_superclass
139
137
  @execution_context_class = Class.new(behaviour_superclass)
138
+ behaviour_superclass.spec_inherited(self) if behaviour_superclass.respond_to?(:spec_inherited)
139
+ @execution_context_class
140
140
  end
141
141
 
142
142
  def behaviour_superclass
@@ -7,7 +7,11 @@ module Spec
7
7
  args, @options = args_and_options(*args)
8
8
  @described_type = args.first unless args.first.is_a?(String)
9
9
  @description = args.shift.to_s
10
- @description << args.shift.to_s unless args.empty?
10
+ unless args.empty?
11
+ suffix = args.shift.to_s
12
+ @description << " " unless suffix =~ /^\s|\.|#/
13
+ @description << suffix
14
+ end
11
15
  end
12
16
 
13
17
  def [](key)
@@ -12,6 +12,7 @@ module Spec
12
12
  end
13
13
 
14
14
  def run(reporter, before_each_block, after_each_block, dry_run, execution_context, timeout=nil)
15
+ @dry_run = dry_run
15
16
  reporter.example_started(description)
16
17
  return reporter.example_finished(description) if dry_run
17
18
 
@@ -39,12 +40,21 @@ module Spec
39
40
  end
40
41
 
41
42
  def generated_description
42
- @generated_description || "NAME NOT GENERATED"
43
+ return @generated_description if @generated_description
44
+ if @dry_run
45
+ "NO NAME (Because of --dry-run)"
46
+ else
47
+ if @failed
48
+ "NO NAME (Because of Error raised in matcher)"
49
+ else
50
+ "NO NAME (Because there were no expectations)"
51
+ end
52
+ end
43
53
  end
44
54
 
45
55
  def setup_example(execution_context, errors, &behaviour_before_block)
46
56
  setup_mocks(execution_context)
47
- Spec::Matchers.description_generated(&@description_generated_proc)
57
+ Spec::Matchers.description_generated(@description_generated_proc)
48
58
 
49
59
  builder = CompositeProcBuilder.new
50
60
  before_proc = builder.proc(&append_errors(errors))
@@ -53,6 +63,7 @@ module Spec
53
63
  execution_context.instance_eval(&behaviour_before_block) if behaviour_before_block
54
64
  return errors.empty?
55
65
  rescue => e
66
+ @failed = true
56
67
  errors << e
57
68
  return false
58
69
  end
@@ -62,6 +73,7 @@ module Spec
62
73
  execution_context.instance_eval(&@example_block)
63
74
  return true
64
75
  rescue Exception => e
76
+ @failed = true
65
77
  errors << e
66
78
  return false
67
79
  end
@@ -84,6 +96,7 @@ module Spec
84
96
 
85
97
  return errors.empty?
86
98
  rescue => e
99
+ @failed = true
87
100
  errors << e
88
101
  return false
89
102
  end
@@ -118,13 +118,13 @@ module Spec
118
118
  # end
119
119
  # end
120
120
  #
121
- # context "Player behaviour" do
121
+ # describe "Player behaviour" do
122
122
  # include CustomGameMatchers
123
123
  # ...
124
124
  # end
125
125
  module Matchers
126
126
  module ModuleMethods
127
- def description_generated(&callback)
127
+ def description_generated(callback)
128
128
  description_generated_callbacks << callback
129
129
  end
130
130
 
@@ -99,10 +99,6 @@ module Spec
99
99
  end
100
100
  end
101
101
 
102
- def parse_line(line_number)
103
- @line_number = line_number.to_i
104
- end
105
-
106
102
  def parse_format(format, out_stream, error_stream)
107
103
  where = out_stream
108
104
  # This funky regexp checks whether we have a FILE_NAME or not
@@ -3,11 +3,11 @@ module Spec
3
3
  unless defined? MAJOR
4
4
  MAJOR = 0
5
5
  MINOR = 9
6
- TINY = 2
6
+ TINY = 3
7
7
  RELEASE_CANDIDATE = nil
8
8
 
9
- # RANDOM_TOKEN: 0.495595173542949
10
- REV = "$LastChangedRevision: 1899 $".match(/LastChangedRevision: (\d+)/)[1]
9
+ # RANDOM_TOKEN: 0.289603753816874
10
+ REV = "$LastChangedRevision: 1916 $".match(/LastChangedRevision: (\d+)/)[1]
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY].join('.')
13
13
  TAG = "REL_#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('_')}".upcase.gsub(/\.|-/, '_')
@@ -206,9 +206,13 @@ module Spec
206
206
  before_all_run_count_run_count.should == 1
207
207
  end
208
208
 
209
- it "should run superclass setup method and before block" do
209
+ it "calls spec_inherited class method" do
210
210
  super_class_before_ran = false
211
211
  super_class = Class.new do
212
+ def self.spec_inherited(mod)
213
+ mod.before {setup}
214
+ end
215
+
212
216
  define_method :setup do
213
217
  super_class_before_ran = true
214
218
  end
@@ -261,12 +265,22 @@ module Spec
261
265
  end
262
266
  @behaviour.inherit super_class
263
267
 
268
+ Behaviour.prepend_before(:all) { fiddle << "Behaviour.prepend_before(:all)" }
264
269
  Behaviour.before(:all) { fiddle << "Behaviour.before(:all)" }
270
+ @behaviour.prepend_before(:all) { fiddle << "prepend_before(:all)" }
265
271
  @behaviour.before(:all) { fiddle << "before(:all)" }
272
+ @behaviour.prepend_before(:each) { fiddle << "prepend_before(:each)" }
266
273
  @behaviour.before(:each) { fiddle << "before(:each)" }
267
274
  @behaviour.it("test") {true}
268
275
  @behaviour.run(@reporter)
269
- fiddle.should == ['Behaviour.before(:all)', 'before(:all)', 'superclass setup', 'before(:each)']
276
+ fiddle.should == [
277
+ 'Behaviour.prepend_before(:all)',
278
+ 'Behaviour.before(:all)',
279
+ 'prepend_before(:all)',
280
+ 'before(:all)',
281
+ 'prepend_before(:each)',
282
+ 'before(:each)'
283
+ ]
270
284
  end
271
285
 
272
286
  it "after callbacks are ordered from local to global" do
@@ -281,12 +295,22 @@ module Spec
281
295
  end
282
296
  @behaviour.inherit super_class
283
297
 
298
+ @behaviour.after(:each) { fiddle << "after(:each)" }
299
+ @behaviour.append_after(:each) { fiddle << "append_after(:each)" }
284
300
  @behaviour.after(:all) { fiddle << "after(:all)" }
301
+ @behaviour.append_after(:all) { fiddle << "append_after(:all)" }
285
302
  Behaviour.after(:all) { fiddle << "Behaviour.after(:all)" }
286
- @behaviour.after(:each) { fiddle << "after(:each)" }
303
+ Behaviour.append_after(:all) { fiddle << "Behaviour.append_after(:all)" }
287
304
  @behaviour.it("test") {true}
288
305
  @behaviour.run(@reporter)
289
- fiddle.should == ['after(:each)', 'superclass teardown', 'after(:all)', 'Behaviour.after(:all)']
306
+ fiddle.should == [
307
+ 'after(:each)',
308
+ 'append_after(:each)',
309
+ 'after(:all)',
310
+ 'append_after(:all)',
311
+ 'Behaviour.after(:all)',
312
+ 'Behaviour.append_after(:all)'
313
+ ]
290
314
  end
291
315
 
292
316
  it "should run superclass teardown method and after block" do
@@ -302,7 +326,7 @@ module Spec
302
326
  @behaviour.after {teardown_ran = true}
303
327
  @behaviour.it("test") {true}
304
328
  @behaviour.run(@reporter)
305
- super_class_teardown_ran.should be_true
329
+ super_class_teardown_ran.should be_false
306
330
  teardown_ran.should be_true
307
331
  @reporter.rspec_verify
308
332
  end
@@ -2,7 +2,9 @@ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  module Spec
4
4
  module DSL
5
- describe Description, " constructed with a single String" do before(:each) {@description = Description.new("abc")}
5
+ describe Description, " constructed with a single String" do
6
+ before(:each) {@description = Description.new("abc")}
7
+
6
8
  it "should provide that string as its name" do
7
9
  @description.description.should == "abc"
8
10
  end
@@ -24,7 +26,9 @@ module Spec
24
26
  end
25
27
  end
26
28
 
27
- describe Description, " constructed with a Type" do before(:each) {@description = Description.new(Behaviour)}
29
+ describe Description, " constructed with a Type" do
30
+ before(:each) {@description = Description.new(Behaviour)}
31
+
28
32
  it "should provide a String representation of that type (fully qualified) as its name" do
29
33
  @description.description.should == "Spec::DSL::Behaviour"
30
34
  end
@@ -33,7 +37,9 @@ module Spec
33
37
  end
34
38
  end
35
39
 
36
- describe Description, " constructed with a Type and a String" do before(:each) {@description = Description.new(Behaviour, " behaving")}
40
+ describe Description, " constructed with a Type and a String" do
41
+ before(:each) {@description = Description.new(Behaviour, " behaving")}
42
+
37
43
  it "should include the type and second String in its name" do
38
44
  @description.description.should == "Spec::DSL::Behaviour behaving"
39
45
  end
@@ -42,6 +48,30 @@ module Spec
42
48
  end
43
49
  end
44
50
 
51
+ describe Description, "constructed with a Type and a String not starting with a space" do
52
+ before(:each) {@description = Description.new(Behaviour, "behaving")}
53
+
54
+ it "should include the type and second String with a space in its name" do
55
+ @description.description.should == "Spec::DSL::Behaviour behaving"
56
+ end
57
+ end
58
+
59
+ describe Description, "constructed with a Type and a String starting with a ." do
60
+ before(:each) {@description = Description.new(Behaviour, ".behaving")}
61
+
62
+ it "should include the type and second String with a space in its name" do
63
+ @description.description.should == "Spec::DSL::Behaviour.behaving"
64
+ end
65
+ end
66
+
67
+ describe Description, "constructed with a Type and a String starting with a #" do
68
+ before(:each) {@description = Description.new(Behaviour, "#behaving")}
69
+
70
+ it "should include the type and second String with a space in its name" do
71
+ @description.description.should == "Spec::DSL::Behaviour#behaving"
72
+ end
73
+ end
74
+
45
75
  describe Description, " constructed with options" do before(:each) {@description = Description.new(Behaviour, :a => "b")}
46
76
  it "should provide its options" do
47
77
  @description[:a].should == "b"
@@ -116,9 +116,31 @@ module Spec
116
116
  example = Example.new("name", :key => 'value')
117
117
  end
118
118
 
119
- it "should report NAME NOT GENERATED when told to use generated description but none is generated" do
120
- example = Example.new(:__generate_description)
121
- @reporter.should_receive(:example_finished).with("NAME NOT GENERATED", :anything, :anything)
119
+ it "should report NO NAME when told to use generated description with --dry-run" do
120
+ example = Example.new(:__generate_description) {
121
+ 5.should == 5
122
+ }
123
+ @reporter.should_receive(:example_finished) do |desc, error, location|
124
+ desc.should == "NO NAME (Because of --dry-run)"
125
+ end
126
+ example.run(@reporter, lambda{}, lambda{}, true, Object.new)
127
+ end
128
+
129
+ it "should report NO NAME when told to use generated description with no expectations" do
130
+ example = Example.new(:__generate_description) {}
131
+ @reporter.should_receive(:example_finished) do |desc, error, location|
132
+ desc.should == "NO NAME (Because there were no expectations)"
133
+ end
134
+ example.run(@reporter, lambda{}, lambda{}, false, Object.new)
135
+ end
136
+
137
+ it "should report NO NAME when told to use generated description and matcher fails" do
138
+ example = Example.new(:__generate_description) do
139
+ 5.should "" # Has no matches? method..
140
+ end
141
+ @reporter.should_receive(:example_finished) do |desc, error, location|
142
+ desc.should == "NO NAME (Because of Error raised in matcher)"
143
+ end
122
144
  example.run(@reporter, nil, nil, nil, Object.new)
123
145
  end
124
146
 
@@ -4,7 +4,7 @@ describe "Matchers should be able to generate their own descriptions" do
4
4
  before(:each) do
5
5
  @desc = nil
6
6
  @callback = lambda { |desc| @desc = desc }
7
- Spec::Matchers.description_generated(&@callback)
7
+ Spec::Matchers.description_generated(@callback)
8
8
  end
9
9
 
10
10
  it "should == expected" do
@@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  module ExampleExpectations
4
4
 
5
5
  class ArbitraryMatcher
6
- def initialize(*args,&block)
7
- if args.last.is_a?Hash
6
+ def initialize(*args, &block)
7
+ if args.last.is_a? Hash
8
8
  @expected = args.last[:expected]
9
9
  end
10
10
  if block_given?
@@ -128,7 +128,7 @@ describe "OptionParser" do
128
128
  options = parse(["--format", "html:test.html"])
129
129
  File.should be_exist('test.html')
130
130
  options.formatters[0].class.should equal(Spec::Runner::Formatter::HtmlFormatter)
131
- FileUtils.rm 'test.html'
131
+ FileUtils.rm 'test.html' rescue nil # Help windows
132
132
  end
133
133
 
134
134
  it "should use noisy backtrace tweaker with b option" do
metadata CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.9.1
3
3
  specification_version: 1
4
4
  name: rspec
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.2
7
- date: 2007-05-03 00:00:00 +02:00
8
- summary: RSpec-0.9.2 (r1899) - BDD for Ruby http://rspec.rubyforge.org/
6
+ version: 0.9.3
7
+ date: 2007-05-06 00:00:00 +02:00
8
+ summary: RSpec-0.9.3 (r1916) - BDD for Ruby http://rspec.rubyforge.org/
9
9
  require_paths:
10
10
  - lib
11
11
  email: rspec-devel@rubyforge.org