Permalink
Browse files

Set each example's instance of the group to nil after processing.

This dereferences the example group instance which contains all of the
example's state, thereby releasing each example for garbage collection
after processing.

Note that this does not dereference state initialized in before(:all),
but those instance variables are cleared out in a separate process.
  • Loading branch information...
1 parent 4ac234e commit 300aac321442ae645e0c8430c333f5aeab0dc00c @dchelimsky dchelimsky committed Feb 22, 2011
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/rspec/core/example.rb
  2. +8 −0 spec/rspec/core/example_spec.rb
@@ -58,7 +58,7 @@ def run(example_group_instance, reporter)
rescue Exception => e
set_exception(e)
ensure
- @example_group_instance.example = nil
+ @example_group_instance = nil
assign_auto_description
end
@@ -33,6 +33,14 @@
end
describe "#run" do
+ it "sets its reference to the example group instance to nil" do
+ group = RSpec::Core::ExampleGroup.describe do
+ example('example') { 1.should eq(1) }
+ end
+ group.run
+ group.examples.first.instance_variable_get("@example_group_instance").should be_nil
+ end
+
it "runs after(:each) when the example passes" do
after_run = false
group = RSpec::Core::ExampleGroup.describe do

0 comments on commit 300aac3

Please sign in to comment.