Open mgudapak opened 10 years ago
Hello @mgudapak,
Testing a factory doesn't make sense. It's only to help you to create proper objects easier. Also trying to test uniqueness this way doesn't make any sense. Probably you'll want to use the shoulda matcher like this:
it { should validate_uniqueness_of(:entity_attribute) }
Disclaimer: I am new to RSpec and trying to build tests on an existing app using the some of the examples in this book. The below is replicating a test similar to the one on page 35 of your PDF.
I have a 'Price' Model which has only one required column 'id' which is unique and set to AUTO_INCREMENT at the database (MySQL) level.
My factory is setup as below
My spec is as follows
The RSpec error I get is as follows
Am I doing something wrong or testing something that I shouldn't be testing with RSpec (since the database will take care of enforcing uniqueness)? I was expecting that the 'DuplicateRecord' error from MySQL would be captured and reported as an error resulting in my test passing - right?
Any pointers would be very helpful. Cheers