Rails 3.1, RSpec: testing model validations

后端 未结 7 1544
不知归路
不知归路 2021-01-30 03:51

I have started my journey with TDD in Rails and have run into a small issue regarding tests for model validations that I can\'t seem to find a solution to. Let\'s say I have a U

相关标签:
7条回答
  • 2021-01-30 04:38

    An easier way to test model validations (and a lot more of active-record) is to use a gem like shoulda or remarkable.

    They will allow to the test as follows:

    describe User
    
      it { should validate_presence_of :name }
    
    end
    
    0 讨论(0)
提交回复
热议问题