specファイルを修正
spec/models/user_spec.rb
require 'spec_helper' describe User do describe '#validate' do before :all do @user = FactoryGirl.build(:user, password: 'murajun1978') end it "正常に保存できる" do expect(@user.save).to be true end context 'login_name' do it "login_nameは数字のみは不可" do @user.login_name = "111" expect(@user.save).to be false end it "login_nameは英字のみは不可" do @user.login_name = "eee" expect(@user.save).to be false end it "login_nameの先頭は必ず英字" do @user.login_name = "111aaa" expect(@user.save).to be false end it "login_nameは必須" do @user.login_name = "" expect(@user.save).to be false end it "login_nameは重複不可" do @user = FactoryGirl.build(:user, login_name: 'user_name_1') expect(@user.save).to be false end end after :all do User.delete_all end end end
正常に保存できる条件でテストしないと意味ない(;・∀・)
( ̄(エ) ̄)彡☆
0 件のコメント:
コメントを投稿