Ravinder Rana
Ravinder Rana

Reputation: 1

Why records are not getting deleted after test/spec

Am using 'devise' gem for authentication and rspec for testing. My problem is after spec execution the test data is not getting cleared from DB, because of this subsequent execution of specs fail. Following is the spec:

describe User do

it "should return a valid user when valid email and password are used" do user = User.new(:email => '[email protected]', :password => 'test123', :password_confirmation => 'test123') user.save user.should be_valid end

end

Is there anything more that i am excepted to do here?

Upvotes: 0

Views: 274

Answers (2)

ianrandmckenzie
ianrandmckenzie

Reputation: 482

In some cases it is common practice to prepare the test db before running specs each time:

rails db:test:prepare

Upvotes: 0

Ramon Tayag
Ramon Tayag

Reputation: 16084

I'm not sure myself. I'm learning how to make gems and I ran across this issue. I added the method in spec_helper:


def purge_db
  [User, Subscription, Dorkus].each {|c| c.delete_all}
end

Spec::Runner.configure do |config|
  config.before(:each) { purge_db }
end         

Upvotes: 0

Related Questions