I'm creating tests for an API with rspec using Mongoid and FactoryGirl. Mongoid is not a problem in production, but when testing API specs like so:
it "renders [person]" do
person = FactoryGirl.create(:person)
get 'persons'
json.count.should eq(1)
end
the model instance being created (in this case Person
) is sometimes not reflected in the database by the time the API call runs, resulting in an error like so:
Failure/Error: json.count.should eq(1)
expected: 1
got: 0
(compared using ==)
How can I create new database entries and block further execution of the spec until I know that the entry is reflected in the database?