Hi all<br><br>I'm having problems with data in my specs - i'm probably just going about things the wrong way though.<br><br>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.<br>
<br>In a before(:all) block, i'm creating a bunch of objects and saving them to the database - like this:<br><br>describe Property, "with a fresh property tree" do<br> before(:all) do<br> @root = Property.new(:name => "Root")<br>
@<a href="http://root.id">root.id</a> = 0 #root.id must be 0 for acts as tree to work properly<br> @root.save<br> @role = @root.children.create(:name => "Job Role")<br> @dept = @root.children.create(:name => "Department")<br>
...etc<br> end<br><br> describe ",standard acts_as_tree methods," do<br> <br> #this test is failing<br> it "class.root" do<br> Property.root.should eql(@root)<br> end<br> end<br><br>
and the fail report from the above test:<br>'Property with a fresh property tree ,standard acts_as_tree methods, class.root' FAILED<br>expected #<Property id: 0, parent_id: nil, name: "Root">, got #<Property id: 976, parent_id: nil, name: "Root"> (using .eql?)<br>
./spec/models/property_spec.rb:50:<br>script/spec:4:<br><br> <br><br>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?<br>