[rspec-users] Rspec-2 around/before(:all) hooks

Mack T.
Tue, 02 Nov 2010 18:54:33 -0000

Rspec-2 around/before(:all) hooks

I''m trying to create several model instances before all of our tests
are
run.  I''m having trouble defining the behavior in my Rspec.configure
block.  I''ve tried before(:all) and around(:all), but to no avail.

before(:all) successfully creates the models, but it appears that
everything in the block passed is rolled back before the test runs:

# spec_helper.rb
config.before(:all) do
  @person = Person.create(:name => ''not here!'')
end

# person_spec.rb
describe Person
  it do
    p Person.where(:short_name => ''not here!'').first #=>
nil
    p @person #=> <Person id: 1050608284, name: "not here!">
    @person.reload #=> Error: Couldn''t find Person with
ID=1050608284
  end
end

It seems that around(:all) is not supported, either.  Is that correct?
This code in the block passed to configure results in a nil.<< error:

# spec_helper.rb
config.around(:all) do
  puts "hai"
  yield
  puts "bai"
end

I''m running rspec-2.0.1 and rails-3.0.0.  Is there a preferred way to
do
this that I''m missing?  Thanks in advance!