[rspec-users] When is spec_helper.rb actually executed?

Scott Taylor mailing_lists at railsnewbie.com
Wed Oct 8 21:52:14 EDT 2008

On Oct 8, 2008, at 7:40 PM, Wes Gamble wrote:

> OK, got it.
> I have a follow-up question though.  If a given spec DID NOT require
> spec_helper.rb, doesn't that imply that the spec would be run against
> the Rails "development" environment.

Basically, the normal operation is that your spec requires  
spec_helper, which eventually requires the test_helper which comes  
with rails, which sets the constant:

RAILS_ENV = "test"

> I just did a test where I printed out the configuration of one of my
> classes DB connnections (e.g. Blah.connection.inspect where Blah is an
> AR model).  And I saw that the "database" setting in this was
> development.  My spec definitely inserts data into the DB.
> I kind of expected to see additional rows in the table in question.
> But I just realized that each spec is probably surrounded by a
> transaction - is that correct?

Yes.  Assuming you have transaction_fixtures = true.  This is how  
rails resets the database between each test (at least after rails 1.2).


More information about the rspec-users mailing list