Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created January 21, 2011 18:01
Show Gist options
  • Save cheeyeo/790094 to your computer and use it in GitHub Desktop.
Save cheeyeo/790094 to your computer and use it in GitHub Desktop.
Rspec optmization techniques borrowed from 37Signals
# method for clearing out instance variables from code blocks
# usage:
Spec::Runner.configure do |config|
.....
config.after(:each) do
scrub_instance_variables
end
end
.......
@@reserved_ivars = %w(@selected @_backtrace @_proxy @data_tem @_implementation @request @loaded_fixtures @controller @method_name @fixture_cache @_result @deliveries @response @test_passed @_assertion_wrapped)
# instance_variables is an actual method in the rspec source code
def scrub_instance_variables
(instance_variables - @@reserved_ivars).each do |ivar|
instance_variable_set(ivar, nil)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment