[rspec-devel] [ rspec-Bugs - Rails Plugin-6375 ] rails_spec does not isolate tests when using database

noreply at rubyforge.org noreply at rubyforge.org
Sat Oct 28 13:49:01 EDT 2006


Bugs - Rails Plugin item #6375, was opened at 2006-10-28 15:23
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=9465&aid=6375&group_id=797

Category: None
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Nobody (None)
Assigned to: Nobody (None)
Summary: rails_spec does not isolate tests when using database

Initial Comment:
Specs are not isolated between runs

I have model Employee with 
  validates_uniqueness_of :login

then in my EmployeeSpec (only 1 context, 1 spec) i execute:
  employee = Employee.new(valid_employee_attributes)
  employee.save.should.be true

I do NOT load fixtures.

When I run this spec for the FIRST time -- it is succeeds.

But when I run it once again (with spec, or with use of rails_spec_server)
it fails:

Spec::Expectations::ExpectationNotMetError in 'New Employee should have all attributes set'
"has already been taken" should be nil

Which means that there is already an Employee with such name.

Then I checked my database server and it showed (SELECT * FROM employees) existing records!!!.

I also fetched all employees within the spec before new record creation:

    ee = Employee.find :all
    ee.each do |x|
      puts "#{x.id} #{x.login}"
    end

which showed records from DB, but there should be no records -- as this is test DB. That means that this test (spec) was not isolated.

I used self.use_transactional_fixtures set to 'true' and 'false'


----------------------------------------------------------------------

>Comment By: David Chelimsky (dchelimsky)
Date: 2006-10-28 17:49

Message:
Since you were playing with self.use_transactional_fixtures, you may have created the record when that was set to false. Can you please manually ensure that your database table is empty, set self.use_transactional_fixtures to true and run the spec twice and report back if this still happens?

Thanks,
David

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=9465&aid=6375&group_id=797


More information about the rspec-devel mailing list