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

noreply at rubyforge.org noreply at rubyforge.org
Sun May 13 18:42:26 EDT 2007


Feature Requests item #10753, was opened at 2007-05-10 17:10
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=10753&group_id=797

Category: runner module
Group: None
>Status: Closed
Priority: 3
Submitted By: Assaf Arkin (assaf)
>Assigned to: Aslak Hellesøy (aslak_hellesoy)
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 }
end

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

----------------------------------------------------------------------

>Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-05-13 18:42

Message:
Fixed in r1951 (What David suggested)

----------------------------------------------------------------------

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

Message:
How about integrating before/after into the config:

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

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: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=10753&group_id=797


More information about the rspec-devel mailing list