[rspec-users] Test data problem (in general and with acts_as_tree)
toastkid.williams at gmail.com
Tue Feb 26 05:55:12 EST 2008
I'm having problems with data in my specs - i'm probably just going about
things the wrong way though.
I'm testing a model (called Property) that uses acts_as_tree, and for now
have just done some specs for the basic acts_as_tree functionality - just as
a sanity check, i thought, but i'm getting fails.
In a before(:all) block, i'm creating a bunch of objects and saving them to
the database - like this:
describe Property, "with a fresh property tree" do
@root = Property.new(:name => "Root")
@root.id = 0 #root.id must be 0 for acts as tree to work properly
@role = @root.children.create(:name => "Job Role")
@dept = @root.children.create(:name => "Department")
describe ",standard acts_as_tree methods," do
#this test is failing
it "class.root" do
and the fail report from the above test:
'Property with a fresh property tree ,standard acts_as_tree methods,
expected #<Property id: 0, parent_id: nil, name: "Root">, got #<Property id:
976, parent_id: nil, name: "Root"> (using .eql?)
My problems seem to be arising from the fact that when i run the test, the
objects i created last time are still in the database. Shouldn't they be
cleared out automatically? This in turn is preventing me from saving root
with an id of 0. If i test all of this stuff in the console it works fine,
but it's failing in my tests, suggesting that my tests are broken. Am i
setting up my data in the wrong way?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users