fotanus
fotanus

Reputation: 20116

how to test if a object was created with rspec?

How to test a method that creates 10 objects User with rspec, but returns a boolean value?

And if it was only one user? There is a cleaner way to test?

Upvotes: 1

Views: 2508

Answers (1)

pjam
pjam

Reputation: 6356

If you want to test that 10 User records were created you could use the expect matcher

expect { my_magic_method }.to change { User.count }.by(10)

and if you also want to test that it returns true

expect(my_magic_method).to be_true

official documentation

Upvotes: 8

Related Questions