[Rspec-devel] use case for: setup_once, teardown_once

itsme213 itsme213 at hotmail.com
Sun May 28 20:16:45 EDT 2006


Setup and teardown are called once for each specify.

Sometimes the setup can be very expensive (e.g. establish a ssh or ftp 
session) and the number of specs large.

context 'Remote Site' do
 require 'net/ftp'
 setup do
  @ftp =  Net::FTP.new(...)
 end
 teardown do
  @ftp.close
 end

 specify 'remote spec 1' do
    @ftp.foo
 end

 specify 'remote spec 2' do
    @ftp.bar
 end

 specify 'remote spec 999' do
    @ftp.baz
 end

end

In such cases it would be quite useful to have a 'once' version. Otherwise 
one might end up munging separate specs into one to avoid the performance 
overhead.

I believe there are other non-performance related use cases for such a 
facility as well, where it would also helps keep specs separate and simple.

Of course, the user would have to be careful about interactions across specs 
in the same context.

Thoughts?




More information about the Rspec-devel mailing list