[rspec-devel] [ rspec-Feature Requests-10753 ] Global before and after

noreply at rubyforge.org noreply at rubyforge.org
Thu May 10 17:21:57 EDT 2007

Feature Requests item #10753, was opened at 2007-05-10 21:10
You can respond by visiting: 

Category: runner module
Group: None
Status: Open
Priority: 3
Submitted By: Assaf Arkin (assaf)
Assigned to: Nobody (None)
Summary: Global before and after

Initial Comment:
Side effects be damned. Unfortunately, we're running test cases in an environment that has a lot of them, so we need to sandbox the environment before every test, and reset it after every test.

Shared behavior works, but you need to include them in every single describe. Redundant. I eventually settled on this, hoping it will not break come 1.0:

Spec::Runner.configure { |config| config.include Sandbox }

class Spec::DSL::Behaviour
  before(:each) { sandbox }
  after(:each) { reset }

How about an easier way that will be a formal part of RSpec?


>Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-10 21:21

How about integrating before/after into the config:

Spec::Runner.configure do |config|
  config.include Sandbox
  config.before(:each) { sandbox }
  config.after(:each) { reset }

This is sort of what we were thinking anyhow - does that work for you?

Note that config.before would happen BEFORE any before blocks in any given behaviour, whereas config.after would happen AFTER any after blocks in the behaviour. There is a way to override that, but it gets complicated.


You can respond by visiting: 

More information about the rspec-devel mailing list