On 29 Jul 2011, at 18:36, John Hinnegan wrote: > I would like to turn this: > > describe TestClass do > before :all do > # set some config > end > after :all do > # restore some config > end > # do a bunch of tests to this > end > > into > > describe TestClass do > with_config_value(X) > > # do a bunch of tests to this > end > > > Basically, I want to include before :all and after :all clauses into a test. > However, I do not want this to apply toa ll tests. > > Thanks in advance.
What you're talking about is generally called a macro. describe TestClass do def self.with_config_value(config) before :all do #set some config end #etc. end with_config_value(x) do # do a bunch of tests end end You can put the macro in a module and either use #extend to make it available in a describe block, or use RSpec's config.extend method to do that automatically. Does that help? cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Hellesøy) Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users