Rails 3.1, RSpec: testing model validations

后端 未结 7 1740
不知归路
不知归路 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:23

    Try this:

    it "should require a username" do
      user = User.create(:username => "")
      user.valid?
      user.errors.should have_key(:username)
    end
    

提交回复
热议问题