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 d0ee3df commit dc684ae9519fdad868522565c7f671fe1d88c932 @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
begin
assign_auto_description
@@ -93,6 +93,14 @@ def assert(val)
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 dc684ae

Please sign in to comment.