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

David Chelimsky dchelimsky at gmail.com
Wed Oct 8 19:46:12 EDT 2008

On Wed, Oct 8, 2008 at 6:40 PM, Wes Gamble <lists at ruby-forum.com> 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.

Not necessarily. Depends on what was loaded before that file. So if
first_spec.rb requires spec_helper.rb and second_spec.rb does not, if
they run in order (first, second) then since the first loads
spec_helper.rb the second will run in the "test" environment.

In that same scenario, if you run second_spec.rb by itself, it will
run in development.

> 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?

As long as you see this in spec_helper.rb (and it is loaded ;) )

  config.use_transactional_fixtures = true

That variable has NOTHING to do with fixtures, but it is rails hook
into running each test (using test/unit) or spec (using rspec) in a

> Wes

More information about the rspec-users mailing list