[rspec-users] Understanding before(:all)

David Richards drichards at showcase60.com
Sat Jan 10 13:59:39 EST 2009

I had, for historic reasons, a setup on a group of specs:

  before(:all) do
    @contents = [%w(this that), %w(this other)]
    @filename = 'test_filename'

When I ran the single file (spec spec/transformer/csv_spec.rb), all my
specs passed.  When I ran the whole project's specs together (spec
spec/), these failed.  Changing before(:all) to before(:each) worked,
but for reasons that are not clear to me.  The before(:all) approach
didn't work because the FasterCSV stub wasn't being set.

Can someone explain why there would be different behavior between
running one file and many files and before(:each) vs. before(:all)?
As far as I understand it, I thought before(:all) was supposed to
always run before a group of specs.  Is it possible that a before
(:all) doesn't work right when calling multiple/all specs at the same


More information about the rspec-users mailing list