before hook in rspec same as before :all?

Jonathan Lin picture Jonathan Lin · Aug 28, 2012 · Viewed 7.9k times · Source

I am wondering whether the before (as seen below) is the same as before :all in RSpec. Sometimes neither :each nor :all is specified and it confuses me as to what before actually does.

require 'spec_helper'

describe "this is a description" do 
  before do # vs. before :all or before :each
   # do something...
  end
end

Would appreciate if anyone can explain the differences, if any. Thanks!

Answer

Jonathan Lin picture Jonathan Lin · Aug 28, 2012

So the answer is No. before is equivalent to before :each, not before :all

Test example.

Update: Wow, this question is popular. To save your head from cognitive overload, I suggest you explicitly state :each or :all.