这是我的规格文件:
require 'spec_helper'
describe User, "references" do
it { should have_and_belong_to_many(:roles) }
it { should belong_to(:account_type) }
it { should belong_to(:primary_sport).class_name("Sport") }
it { should belong_to(:school) }
it { should belong_to(:city) }
end
describe User, "factory" do
before(:each) do
@user = FactoryGirl.create(:user)
end
it "is invalid with no email" do
@user.email = nil
@user.should_not be_valid
end
it "is valid with email" do
@user.should be_valid
end
end
工厂:
FactoryGirl.define do
factory :user do
email Faker::Internet.email
password "password"
password_confirmation "password"
agreed_to_age_requirements true
end
end
我试图“测试”但不确定如何 100% 的部分是检查以确保在创建用户时电子邮件地址不为零。