2
我想寫一個RSpec測試,如果不同的身份具有相同的值(檢查的唯一性提供商和id)
這裏,將檢測Rspec的測試是我工作的測試。我只是種撒了一些廢話到它,因爲我越來越絕望......的唯一性/重複值
context "no duplicate values should exist" do
identity1 = subject { Factory.create(:valid_identity) }
it { should be_valid }
identity2 = identity1
it { should validate_uniqueness_of(:id) }
it { should have(1).error_on(:id) }
it { should validate_uniqueness_of(:provider) }
it { should have(1).error_on(:provider) }
end
爲了讓你我已經習慣了結構的想法,我已經寫了基本測試,如下面的一個如果可能的話,我想堅持到同類型的結構
context "when created without a name" do
subject { Brand.create Factory.build(:valid_brand, :name => nil).attributes }
it { should be_invalid }
it { should have(1).error_on(:name) }
specify { subject.errors[:name].should include "can't be blank" }
end
我的身份廠是這樣的:
Factory.define :valid_identity, :class => Identity do |identity|
identity.participant {|participant| participant.association(:valid_participant) }
identity.provider "twitter"
identity.extid '11111'
end
任何幫助表示讚賞!