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

Mack T. lists at ruby-forum.com
Tue Nov 2 14:54:33 EDT 2010

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!')

# 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

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"
  puts "bai"

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!

Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list