#set speeds up RSpec test suites by persisting records once
= rspec-set {}[https://travis-ci.org/pcreux/rspec-set]
#set is a little RSpec helper that speeds-up drastically integration tests that relies on active record objects.
#set takes advantage of the fact that RSpec rails runs each examples in SQL transactions. Since all the changes made to the database are rolledback after each example we can create an active record object before all examples and use it in each examples without any collisions as long as we reload the object from the database before each example.
#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.
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 one (and only one!) 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 on_time" do flight.should be_on_time endit "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.
You can find more examples in https://github.com/pcreux/rspec-set/blob/master/features/lib/rspec-set.feature
== Notes
== Install
Add rspec-set to you Gemfile
gem 'rspec-set'
and replace calls to #let creating active record objects by #set.
== TODO
== Contributing to rspec-set
== Copyright
Copyright (c) 2010 Philippe Creux. See LICENSE.txt for further details.