rspec-core 2.0.0.beta.13 → 2.0.0.beta.14

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ source "http://rubygems.org"
2
+
1
3
  gem "bundler"
2
4
  gem "rake"
3
5
  gem "jeweler"
@@ -11,4 +13,9 @@ gem "flexmock"
11
13
  gem "rspec-core", :path => "."
12
14
  gem "rspec-expectations", :path => "../rspec-expectations"
13
15
  gem "rspec-mocks", :path => "../rspec-mocks"
14
- gem "ruby-debug"
16
+ if RUBY_VERSION.to_s =~ /1.9.1/
17
+ gem "ruby-debug19"
18
+ elsif RUBY_VERSION.to_s =~ /1.9.2/
19
+ else
20
+ gem "ruby-debug"
21
+ end
@@ -63,6 +63,15 @@ Use the documentation formatter to see the resulting spec:
63
63
  Finished in 0.000379 seconds
64
64
  1 example, 0 failures
65
65
 
66
+ ## Learn more
67
+
68
+ While not comprehensive yet, you can learn quite a lot from the Cucumber
69
+ features in the [features
70
+ directory](http://github.com/rspec/rspec-core/tree/master/features/). If there
71
+ is a feature that is not documented there, or you find them insufficient to
72
+ understand how to use a feature, please submit issues to
73
+ [http://github.com/rspec/rspec-core/issues](http://github.com/rspec/rspec-core/issues).
74
+
66
75
  #### Also see
67
76
 
68
77
  * [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta.13
1
+ 2.0.0.beta.14
@@ -47,3 +47,21 @@ Feature: exit status
47
47
  """
48
48
  1 example, 1 failure
49
49
  """
50
+
51
+ Scenario: exit with 0 when no examples are run
52
+ Given a file named "spec/a_no_examples_spec.rb" with:
53
+ """
54
+ """
55
+ And a file named "spec/b_one_example_spec.rb" with:
56
+ """
57
+ describe "something" do
58
+ it "does something" do
59
+ end
60
+ end
61
+ """
62
+
63
+ When I run "rspec spec"
64
+ Then it should pass with:
65
+ """
66
+ 1 example, 0 failures
67
+ """
@@ -24,3 +24,21 @@ Feature: Nested example groups
24
24
  Then I should see matching /^Some Object/
25
25
  And I should see matching /^\s+with some more context/
26
26
  And I should see matching /^\s+with some other context/
27
+
28
+ Scenario: failure in outer group continues to run inner groups
29
+ Given a file named "nested_example_groups.rb" with:
30
+ """
31
+ describe "something" do
32
+ it "fails" do
33
+ raise "failure"
34
+ end
35
+
36
+ context "nested" do
37
+ it "passes" do
38
+ end
39
+ end
40
+ end
41
+ """
42
+ When I run "rspec ./nested_example_groups.rb -fdoc"
43
+ Then I should see "2 examples, 1 failure"
44
+ And I should see "passes"
@@ -0,0 +1,277 @@
1
+ Feature: around hooks
2
+
3
+ As a developer using RSpec
4
+ I want to run the examples as part of a block given to a an arbitary function
5
+ So that I can control the environment in which it is run
6
+
7
+ Scenario: around hooks defined in a group are run
8
+ Given a file named "ensure_around_blocks_are_run.rb" with:
9
+ """
10
+ describe "around filter" do
11
+ around(:each) do |example|
12
+ puts "around each before"
13
+ example.run
14
+ puts "around each after"
15
+ end
16
+
17
+ it "gets run in order" do
18
+ puts "in the example"
19
+ end
20
+ end
21
+ """
22
+ When I run "rspec ./ensure_around_blocks_are_run.rb"
23
+ Then I should see matching:
24
+ """
25
+ around each before
26
+ in the example
27
+ around each after
28
+ """
29
+
30
+ Scenario: around hooks defined globally are run
31
+ Given a file named "ensure_around_blocks_are_run.rb" with:
32
+ """
33
+ RSpec.configure do |c|
34
+ c.around(:each) do |example|
35
+ puts "around each before"
36
+ example.run
37
+ puts "around each after"
38
+ end
39
+ end
40
+
41
+ describe "around filter" do
42
+ it "gets run in order" do
43
+ puts "in the example"
44
+ end
45
+ end
46
+ """
47
+ When I run "rspec ./ensure_around_blocks_are_run.rb"
48
+ Then I should see matching:
49
+ """
50
+ around each before
51
+ in the example
52
+ around each after
53
+ """
54
+
55
+ Scenario: before/after(:each) hooks are wrapped by the around hook
56
+ Given a file named "ensure_around_blocks_are_run.rb" with:
57
+ """
58
+ describe "around filter" do
59
+ around(:each) do |example|
60
+ puts "around each before"
61
+ example.run
62
+ puts "around each after"
63
+ end
64
+
65
+ before(:each) do
66
+ puts "before each"
67
+ end
68
+
69
+ after(:each) do
70
+ puts "after each"
71
+ end
72
+
73
+ it "gets run in order" do
74
+ puts "in the example"
75
+ end
76
+ end
77
+ """
78
+ When I run "rspec ./ensure_around_blocks_are_run.rb"
79
+ Then I should see matching:
80
+ """
81
+ around each before
82
+ before each
83
+ in the example
84
+ after each
85
+ around each after
86
+ """
87
+
88
+ Scenario: before/after(:hooks) hooks are NOT wrapped by the around hook
89
+ Given a file named "ensure_around_blocks_are_run.rb" with:
90
+ """
91
+ describe "around filter" do
92
+ around(:each) do |example|
93
+ puts "around each before"
94
+ example.run
95
+ puts "around each after"
96
+ end
97
+
98
+ before(:all) do
99
+ puts "before all"
100
+ end
101
+
102
+ after(:all) do
103
+ puts "after all"
104
+ end
105
+
106
+ it "gets run in order" do
107
+ puts "in the example"
108
+ end
109
+ end
110
+ """
111
+ When I run "rspec ./ensure_around_blocks_are_run.rb"
112
+ Then I should see matching:
113
+ """
114
+ before all
115
+ around each before
116
+ in the example
117
+ around each after
118
+ .after all
119
+ """
120
+
121
+ Scenario: examples run by an around block should run in the configured context
122
+ Given a file named "around_block_with_context.rb" with:
123
+ """
124
+ module IncludedInConfigureBlock
125
+ def included_in_configure_block; true; end
126
+ end
127
+
128
+ Rspec.configure do |c|
129
+ c.include IncludedInConfigureBlock
130
+ end
131
+
132
+ describe "around filter" do
133
+ around(:each) do |example|
134
+ example.run
135
+ end
136
+
137
+ it "runs the example in the correct context" do
138
+ included_in_configure_block.should be_true
139
+ end
140
+ end
141
+ """
142
+ When I run "rspec ./around_block_with_context.rb"
143
+ Then I should see "1 example, 0 failure"
144
+
145
+ Scenario: implicitly pending examples should be detected as Not Yet Implemented
146
+ Given a file named "around_block_with_implicit_pending_example.rb" with:
147
+ """
148
+ describe "implicit pending example" do
149
+ around(:each) do |example|
150
+ example.run
151
+ end
152
+
153
+ it "should be detected as Not Yet Implemented"
154
+ end
155
+ """
156
+ When I run "rspec ./around_block_with_implicit_pending_example.rb"
157
+ Then I should see "1 example, 0 failures, 1 pending"
158
+ And I should see "implicit pending example should be detected as Not Yet Implemented (Not Yet Implemented)"
159
+
160
+
161
+ Scenario: explicitly pending examples should be detected as pending
162
+ Given a file named "around_block_with_explicit_pending_example.rb" with:
163
+ """
164
+ describe "explicit pending example" do
165
+ around(:each) do |example|
166
+ example.run
167
+ end
168
+
169
+ it "should be detected as pending" do
170
+ pending
171
+ end
172
+ end
173
+ """
174
+ When I run "rspec ./around_block_with_explicit_pending_example.rb"
175
+ Then I should see "1 example, 0 failures, 1 pending"
176
+ And I should see "explicit pending example should be detected as pending (No reason given)"
177
+
178
+ Scenario: multiple around hooks in the same scope are all run
179
+ Given a file named "around_hooks_in_same_scope.rb" with:
180
+ """
181
+ describe "if there are multiple around hooks in the same scope" do
182
+ around(:each) do |example|
183
+ puts "first around hook before"
184
+ example.run
185
+ puts "first around hook after"
186
+ end
187
+
188
+ around(:each) do |example|
189
+ puts "second around hook before"
190
+ example.run
191
+ puts "second around hook after"
192
+ end
193
+
194
+ it "they should all be run" do
195
+ puts "in the example"
196
+ 1.should == 1
197
+ end
198
+ end
199
+ """
200
+ When I run "rspec ./around_hooks_in_same_scope.rb"
201
+ Then I should see "1 example, 0 failure"
202
+ And I should see matching:
203
+ """
204
+ first around hook before
205
+ second around hook before
206
+ in the example
207
+ second around hook after
208
+ first around hook after
209
+ """
210
+
211
+ Scenario: around hooks in outer scopes are run
212
+ Given a file named "around_hooks_in_outer_scope.rb" with:
213
+ """
214
+ describe "if there are around hooks in an outer scope" do
215
+ around(:each) do |example|
216
+ puts "first outermost around hook before"
217
+ example.run
218
+ puts "first outermost around hook after"
219
+ end
220
+
221
+ around(:each) do |example|
222
+ puts "second outermost around hook before"
223
+ example.run
224
+ puts "second outermost around hook after"
225
+ end
226
+
227
+ describe "outer scope" do
228
+ around(:each) do |example|
229
+ puts "first outer around hook before"
230
+ example.run
231
+ puts "first outer around hook after"
232
+ end
233
+
234
+ around(:each) do |example|
235
+ puts "second outer around hook before"
236
+ example.run
237
+ puts "second outer around hook after"
238
+ end
239
+
240
+ describe "inner scope" do
241
+ around(:each) do |example|
242
+ puts "first inner around hook before"
243
+ example.run
244
+ puts "first inner around hook after"
245
+ end
246
+
247
+ around(:each) do |example|
248
+ puts "second inner around hook before"
249
+ example.run
250
+ puts "second inner around hook after"
251
+ end
252
+
253
+ it "they should all be run" do
254
+ puts "in the example"
255
+ end
256
+ end
257
+ end
258
+ end
259
+ """
260
+ When I run "rspec ./around_hooks_in_outer_scope.rb"
261
+ Then I should see "1 example, 0 failure"
262
+ And I should see matching:
263
+ """
264
+ first outermost around hook before
265
+ second outermost around hook before
266
+ first outer around hook before
267
+ second outer around hook before
268
+ first inner around hook before
269
+ second inner around hook before
270
+ in the example
271
+ second inner around hook after
272
+ first inner around hook after
273
+ second outer around hook after
274
+ first outer around hook after
275
+ second outermost around hook after
276
+ first outermost around hook after
277
+ """
@@ -169,8 +169,8 @@ EOM
169
169
  end
170
170
 
171
171
  def formatter=(formatter_to_use)
172
- if string_const?(formatter_to_use) && Object.const_defined?(formatter_to_use)
173
- formatter_class = Object.const_get(formatter_to_use)
172
+ if string_const?(formatter_to_use) && (class_name = eval(formatter_to_use)).is_a?(Class)
173
+ formatter_class = class_name
174
174
  elsif formatter_to_use.is_a?(Class)
175
175
  formatter_class = formatter_to_use
176
176
  else
@@ -31,70 +31,78 @@ module RSpec
31
31
  alias_method :behaviour, :example_group
32
32
 
33
33
  def run(example_group_instance, reporter)
34
+ start
34
35
  @in_block = false
35
36
  @example_group_instance = example_group_instance
36
37
  @example_group_instance.example = self
37
38
 
38
- run_started
39
-
40
39
  exception = nil
41
40
 
42
- begin
43
- run_before_each
44
- pending_declared_in_example = catch(:pending_declared_in_example) do
41
+ the_example = lambda do
42
+ begin
43
+ run_before_each
45
44
  @in_block = true
46
- if @example_group_class.hooks[:around][:each].empty?
47
- @example_group_instance.instance_eval(&example_block) unless pending
48
- else
49
- @example_group_class.hooks[:around][:each].first.call(AroundProxy.new(self, &example_block))
50
- end
51
- throw :pending_declared_in_example, false
45
+ @example_group_instance.instance_eval(&example_block) unless pending
46
+ rescue Exception => e
47
+ exception = e
48
+ ensure
49
+ @in_block = false
50
+ run_after_each
52
51
  end
53
- rescue Exception => e
54
- exception = e
55
- ensure
56
- @in_block = false
57
- assign_auto_description
58
52
  end
59
53
 
60
54
  begin
61
- run_after_each
55
+ pending_declared_in_example = catch(:pending_declared_in_example) do
56
+ around_hooks(@example_group_class, @example_group_instance, the_example).call
57
+ throw :pending_declared_in_example, false
58
+ end
62
59
  rescue Exception => e
63
- exception ||= e
60
+ exception = e
64
61
  ensure
65
62
  @example_group_instance.example = nil
63
+ assign_auto_description
66
64
  end
67
65
 
68
66
  if exception
69
67
  run_failed(reporter, exception)
68
+ false
70
69
  elsif pending_declared_in_example
71
70
  run_pending(reporter, pending_declared_in_example)
71
+ true
72
72
  elsif pending
73
73
  run_pending(reporter, 'Not Yet Implemented')
74
+ true
74
75
  else
75
76
  run_passed(reporter)
77
+ true
76
78
  end
77
79
  end
78
80
 
79
81
  private
80
82
 
81
- def run_started
83
+ def around_hooks(example_group_class, example_group_instance, the_example)
84
+ hooks = RSpec.configuration.hooks[:around][:each]
85
+ hooks.push example_group_class.ancestors.reverse.map{|a| a.hooks[:around][:each]}
86
+ hooks.flatten.reverse.inject(the_example) do |accum, hook|
87
+ def accum.run; call; end
88
+ lambda { example_group_instance.instance_exec(accum, &hook) }
89
+ end
90
+ end
91
+
92
+ def start
82
93
  record_results :started_at => Time.now
83
94
  end
84
95
 
85
96
  def run_passed(reporter=nil)
86
97
  run_finished reporter, 'passed'
87
- true
88
98
  end
89
99
 
90
100
  def run_pending(reporter, message)
91
101
  run_finished reporter, 'pending', :pending_message => message
92
- true
93
102
  end
94
103
 
95
104
  def run_failed(reporter, exception)
96
105
  run_finished reporter, 'failed', :exception_encountered => exception
97
- false
98
106
  end
99
107
 
100
108
  def run_finished(reporter, status, results={})
@@ -171,8 +171,9 @@ module RSpec
171
171
  reporter.add_example_group(self)
172
172
  begin
173
173
  eval_before_alls(example_group_instance)
174
- run_examples(example_group_instance, reporter) &&
175
- children.map {|child| child.run(reporter)}.all?
174
+ result_for_this_group = run_examples(example_group_instance, reporter)
175
+ results_for_descendants = children.map {|child| child.run(reporter)}.all?
176
+ result_for_this_group && results_for_descendants
176
177
  ensure
177
178
  eval_after_alls(example_group_instance)
178
179
  end
@@ -39,7 +39,6 @@ module RSpec
39
39
  end
40
40
 
41
41
  def around(scope=:each, &block)
42
- RSpec::deprecate("around", "before and after")
43
42
  hooks[:around][scope] << block
44
43
  end
45
44
 
@@ -62,30 +62,11 @@ module RSpec
62
62
  if files_to_run.empty?
63
63
  puts "No examples matching #{pattern} could be found"
64
64
  else
65
- cmd_parts = [ '-Ilib', '-Ispec' ]
66
- cmd_parts << "-w" if warning
67
-
68
- if rcov
69
- command_to_run = rcov_command(cmd_parts)
70
- command_to_run.inspect if verbose
71
-
72
- unless system(command_to_run)
73
- STDERR.puts failure_message if failure_message
74
- raise("#{command_to_run} failed") if fail_on_error
75
- end
76
- else
77
- cmd_parts.concat(files_to_run)
78
- puts cmd.inspect if verbose
79
-
80
- require 'rspec/core'
81
- RSpec::Core::Runner.disable_at_exit_hook!
82
-
83
- unless RSpec::Core::Runner.run(cmd_parts, $stderr, $stdout)
84
- STDERR.puts failure_message if failure_message
85
- raise("RSpec::Core::Runner.run with args #{cmd_parts.inspect} failed") if fail_on_error
86
- end
65
+ puts spec_command.inspect if verbose
66
+ unless system(spec_command)
67
+ STDERR.puts failure_message if failure_message
68
+ raise("#{spec_command} failed") if fail_on_error
87
69
  end
88
-
89
70
  end
90
71
  end
91
72
  end
@@ -97,14 +78,18 @@ module RSpec
97
78
  FileList[ pattern ].to_a
98
79
  end
99
80
 
100
- private
101
-
102
- def rcov_command(cmd_parts)
103
- cmd_parts.unshift runner_options
104
- cmd_parts.unshift runner
105
- cmd_parts.unshift bundler
106
- cmd_parts += files_to_run.map { |fn| %["#{fn}"] }
107
- cmd_parts.join(" ")
81
+ private
82
+
83
+ def spec_command
84
+ @spec_command ||= begin
85
+ cmd_parts = %w[-Ilib -Ispec]
86
+ cmd_parts << "-w" if warning
87
+ cmd_parts.unshift runner_options
88
+ cmd_parts.unshift runner
89
+ cmd_parts.unshift bundler
90
+ cmd_parts += files_to_run.map { |fn| %["#{fn}"] }
91
+ cmd_parts.join(" ")
92
+ end
108
93
  end
109
94
 
110
95
  def runner
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-core}
8
- s.version = "2.0.0.beta.13"
8
+ s.version = "2.0.0.beta.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chad Humphries", "David Chelimsky"]
12
- s.date = %q{2010-06-23}
12
+ s.date = %q{2010-06-27}
13
13
  s.description = %q{RSpec runner and example groups}
14
14
  s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
15
15
  s.executables = ["rspec", "spec"]
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
41
41
  "features/example_groups/nested_groups.feature",
42
42
  "features/filtering/inclusion_filters.feature",
43
43
  "features/formatters/custom_formatter.feature",
44
+ "features/hooks/around_hooks.feature",
44
45
  "features/hooks/before_and_after_hooks.feature",
45
46
  "features/hooks/described_class.feature",
46
47
  "features/hooks/halt.feature",
@@ -134,7 +135,7 @@ Gem::Specification.new do |s|
134
135
  s.homepage = %q{http://github.com/rspec/rspec-core}
135
136
  s.post_install_message = %q{**************************************************
136
137
 
137
- Thank you for installing rspec-core-2.0.0.beta.13
138
+ Thank you for installing rspec-core-2.0.0.beta.14
138
139
 
139
140
  **************************************************
140
141
  }
@@ -142,7 +143,7 @@ Gem::Specification.new do |s|
142
143
  s.require_paths = ["lib"]
143
144
  s.rubyforge_project = %q{rspec}
144
145
  s.rubygems_version = %q{1.3.6}
145
- s.summary = %q{rspec-core-2.0.0.beta.13}
146
+ s.summary = %q{rspec-core-2.0.0.beta.14}
146
147
  s.test_files = [
147
148
  "spec/autotest/failed_results_re_spec.rb",
148
149
  "spec/autotest/rspec_spec.rb",
@@ -185,19 +186,19 @@ Gem::Specification.new do |s|
185
186
  s.specification_version = 3
186
187
 
187
188
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
188
- s.add_development_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.13"])
189
- s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.13"])
189
+ s.add_development_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.14"])
190
+ s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.14"])
190
191
  s.add_development_dependency(%q<cucumber>, [">= 0.5.3"])
191
192
  s.add_development_dependency(%q<autotest>, [">= 4.2.9"])
192
193
  else
193
- s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.13"])
194
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.13"])
194
+ s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.14"])
195
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.14"])
195
196
  s.add_dependency(%q<cucumber>, [">= 0.5.3"])
196
197
  s.add_dependency(%q<autotest>, [">= 4.2.9"])
197
198
  end
198
199
  else
199
- s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.13"])
200
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.13"])
200
+ s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.14"])
201
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.14"])
201
202
  s.add_dependency(%q<cucumber>, [">= 0.5.3"])
202
203
  s.add_dependency(%q<autotest>, [">= 4.2.9"])
203
204
  end
@@ -247,11 +247,17 @@ module RSpec::Core
247
247
  end
248
248
 
249
249
  it "sets a formatter based on its class name" do
250
- Object.const_set("CustomFormatter",Class.new(Formatters::BaseFormatter))
250
+ Object.const_set("CustomFormatter", Class.new(Formatters::BaseFormatter))
251
251
  config.formatter = "CustomFormatter"
252
252
  config.formatter.should be_an_instance_of(CustomFormatter)
253
253
  end
254
-
254
+
255
+ it "sets a formatter based on its class fully qualified name" do
256
+ RSpec.const_set("CustomFormatter", Class.new(Formatters::BaseFormatter))
257
+ config.formatter = "RSpec::CustomFormatter"
258
+ config.formatter.should be_an_instance_of(RSpec::CustomFormatter)
259
+ end
260
+
255
261
  it "raises ArgumentError if formatter is unknown" do
256
262
  lambda { config.formatter = :progresss }.should raise_error(ArgumentError)
257
263
  end
@@ -277,13 +283,13 @@ module RSpec::Core
277
283
  config.line_number = '37'
278
284
  config.filter.should == {:line_number => 37}
279
285
  end
280
-
286
+
281
287
  it "overrides :focused" do
282
288
  config.filter_run :focused => true
283
289
  config.line_number = '37'
284
290
  config.filter.should == {:line_number => 37}
285
291
  end
286
-
292
+
287
293
  it "prevents :focused" do
288
294
  config.line_number = '37'
289
295
  config.filter_run :focused => true
@@ -319,7 +325,7 @@ module RSpec::Core
319
325
  config.debug = false
320
326
  end
321
327
  end
322
-
328
+
323
329
  describe "#output=" do
324
330
  it "sets the output" do
325
331
  output = mock("output")
@@ -29,6 +29,26 @@ module RSpec::Core
29
29
  examples_run.should have(1).example
30
30
  end
31
31
 
32
+ context "with a failure in the top level group" do
33
+ it "runs its children " do
34
+ examples_run = []
35
+ group = ExampleGroup.describe("parent") do
36
+ it "fails" do
37
+ examples_run << example
38
+ raise "fail"
39
+ end
40
+ describe("child") do
41
+ it "does something" do
42
+ examples_run << example
43
+ end
44
+ end
45
+ end
46
+
47
+ group.run_all
48
+ examples_run.should have(2).examples
49
+ end
50
+ end
51
+
32
52
  describe "descendants" do
33
53
  it "returns self + all descendants" do
34
54
  group = ExampleGroup.describe("parent") do
@@ -133,7 +153,6 @@ module RSpec::Core
133
153
  group = ExampleGroup.describe(String) do
134
154
  describe :symbol do
135
155
  example "describes is String" do
136
- debugger
137
156
  described_class.should eq(String)
138
157
  end
139
158
  end
@@ -96,6 +96,29 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
96
96
  group.run_all
97
97
  after_run.should be_true, "expected after(:each) to be run"
98
98
  end
99
+
100
+ it "wraps before/after(:each) inside around" do
101
+ results = []
102
+ group = RSpec::Core::ExampleGroup.describe do
103
+ around(:each) do |e|
104
+ results << "around (before)"
105
+ e.run
106
+ results << "around (after)"
107
+ end
108
+ before(:each) { results << "before" }
109
+ after(:each) { results << "after" }
110
+ example { results << "example" }
111
+ end
112
+
113
+ group.run_all
114
+ results.should eq([
115
+ "around (before)",
116
+ "before",
117
+ "example",
118
+ "after",
119
+ "around (after)"
120
+ ])
121
+ end
99
122
  end
100
123
 
101
124
  describe "#in_block?" do
@@ -3,10 +3,54 @@ require "spec_helper"
3
3
  module RSpec::Core
4
4
  describe Hooks do
5
5
  describe "#around" do
6
- it "is deprecated" do
7
- RSpec.should_receive(:deprecate)
8
- subject = Object.new.extend(Hooks)
9
- subject.around(:each) {}
6
+ context "when not running the example within the arond block" do
7
+ it "does not run the example" do
8
+ examples = []
9
+ group = ExampleGroup.describe do
10
+ around do |example|
11
+ end
12
+ it "foo" do
13
+ examples << self
14
+ end
15
+ end
16
+ group.run_all
17
+ examples.should have(0).example
18
+ end
19
+ end
20
+
21
+ context "when running the example within the around block" do
22
+ it "runs the example" do
23
+ examples = []
24
+ group = ExampleGroup.describe do
25
+ around do |example|
26
+ example.run
27
+ end
28
+ it "foo" do
29
+ examples << self
30
+ end
31
+ end
32
+ group.run_all
33
+ examples.should have(1).example
34
+ end
35
+ end
36
+
37
+ context "when running the example within a block passed to a method" do
38
+ it "runs the example" do
39
+ examples = []
40
+ group = ExampleGroup.describe do
41
+ def yielder
42
+ yield
43
+ end
44
+ around do |example|
45
+ yielder { example.run }
46
+ end
47
+ it "foo" do
48
+ examples << self
49
+ end
50
+ end
51
+ group.run_all
52
+ examples.should have(1).example
53
+ end
10
54
  end
11
55
  end
12
56
  end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 13
11
- version: 2.0.0.beta.13
10
+ - 14
11
+ version: 2.0.0.beta.14
12
12
  platform: ruby
13
13
  authors:
14
14
  - Chad Humphries
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-06-23 00:00:00 -05:00
20
+ date: 2010-06-27 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -32,8 +32,8 @@ dependencies:
32
32
  - 0
33
33
  - 0
34
34
  - beta
35
- - 13
36
- version: 2.0.0.beta.13
35
+ - 14
36
+ version: 2.0.0.beta.14
37
37
  requirement: *id001
38
38
  prerelease: false
39
39
  - !ruby/object:Gem::Dependency
@@ -48,8 +48,8 @@ dependencies:
48
48
  - 0
49
49
  - 0
50
50
  - beta
51
- - 13
52
- version: 2.0.0.beta.13
51
+ - 14
52
+ version: 2.0.0.beta.14
53
53
  requirement: *id002
54
54
  prerelease: false
55
55
  - !ruby/object:Gem::Dependency
@@ -114,6 +114,7 @@ files:
114
114
  - features/example_groups/nested_groups.feature
115
115
  - features/filtering/inclusion_filters.feature
116
116
  - features/formatters/custom_formatter.feature
117
+ - features/hooks/around_hooks.feature
117
118
  - features/hooks/before_and_after_hooks.feature
118
119
  - features/hooks/described_class.feature
119
120
  - features/hooks/halt.feature
@@ -210,7 +211,7 @@ licenses: []
210
211
  post_install_message: |
211
212
  **************************************************
212
213
 
213
- Thank you for installing rspec-core-2.0.0.beta.13
214
+ Thank you for installing rspec-core-2.0.0.beta.14
214
215
 
215
216
  **************************************************
216
217
 
@@ -240,7 +241,7 @@ rubyforge_project: rspec
240
241
  rubygems_version: 1.3.6
241
242
  signing_key:
242
243
  specification_version: 3
243
- summary: rspec-core-2.0.0.beta.13
244
+ summary: rspec-core-2.0.0.beta.14
244
245
  test_files:
245
246
  - spec/autotest/failed_results_re_spec.rb
246
247
  - spec/autotest/rspec_spec.rb