= rspec-set #set is a little helper for RSpec to speed-up your specs. #set can be used as a replacement of #let: #set will create the resource before(:all) your examples and will reload the resource before(:each) example. #let on the other hand creates the resource for every single example. You can drastically improve the time spent to run your specs. On an application with 3000 examples we decreased the specs duration by 70%! == Usage The following code will create a flight before running the examples and reload the flight from the DB before each example. require 'spec_helper' describe Flight do set(:flight) do Flight.create! end it "should be cancellable" do flight.cancel flight.should be_cancelled end it "should be delayable" do flight.delay flight.should be_delayed end end === How does that work? RSpec wraps each example in an SQL transaction which gets rolled back at the end of each example. #set creates a flight once before running any example. Each example uses this flight and changes its state. Since RSpec rolls back the SQL transaction, the flight gets back to its initial state before each example. #set takes care of reloading the flight from the DB before each example. Examples won't affect each others then. == Notes * #set works only with ActiveRecord objects saved to the DB so far. * The record created by #set won't be deleted from the database. I encourage you to use DatabaseCleaner with the :truncation strategy to clean up your database. So far in RSpec 2.0, before(:all) runs before all describe/context blocks while after(:all) runs after every single describe/context/it blocks. Just make sure that you call DatabaseCleaner.clean in a before(:all) or after(:suite) then. :) * #set does not handle multi-level transactions. * You will have to call DatabaseCleaner.clean before(:all) specs which rely on having an empty database. #set don't clean the database for you. == TODO * add cukes * support non active record objects * support non saved active record objects * make before(:all) running in a transaction - See: http://rhnh.net/2010/10/06/transactional-before-all-with-rspec-and-datamapper * support multi-level transactions == Contributing to rspec-set * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it * Fork the project * Start a feature/bugfix branch * Commit and push until you are happy with your contribution * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. == Copyright Copyright (c) 2010 Philippe Creux. See LICENSE.txt for further details.