我有以下用户类
class User
include MongoMapper::Document
key :email, String, :unique => true
end
和我的 rspec 代码
before do
@user = FactoryGirl.create(:user)
end
describe "when email address is already taken" do
before do
user_with_same_email = @user.dup
user_with_same_email.email = @user.email
user_with_same_email.save
end
it { should_not be_valid }
end
引发以下错误
1) User when email address is already taken
Failure/Error: it { should_not be_valid }
expected #<User _id: BSON::ObjectId('5236bec5ebe8660fcb00001a'), accepted_tender_ids: [], avatar: #<Avatar _id: BSON::ObjectId('5236bec3ebe8660fcb000001'), digest: "c7358a60a79905a7d4e3383ba905f1baaab278b06a6f751971344cb91763068f", image: "c7358a60a79905a7d4e3383ba905f1baaab278b06a6f751971344cb91763068f">, busy: false, completed_count: 0, completed_tender_ids: [], confirmed: true, dialogs: [], dislikes: 0, email: "maurice_langworth@treutel.com", role: "customer", subspecializations: [], type: "personal"> not to be valid
预期用户无效但有效