Rails 3.1, RSpec: testing model validations

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

    in new version rspec, you should use expect instead should, otherwise you'll get warning:

    it "should have valid factory" do
        expect(FactoryGirl.build(:user)).to be_valid
    end
    
    it "should require a username" do
        expect(FactoryGirl.build(:user, :username => "")).not_to be_valid
    end
    

提交回复
热议问题