我在 rspec 2 上进行了测试,因此如果 partner_id 存在,则 Agency_id 不应该:
describe "tests on deals models validations for AGENCY_ID" do
context "if partner_id present" do
before { subject.stub(:partner_id) { 2 } }
it { should validate_absence_of(:agency_id) }
end
如何使用 rspec 3 做到这一点?
我试过了:
it "should reject model if agency_id present AND partner_id is also already present" do
allow(subject).to receive(:partner_id) { 2 }
expect(Customer.new).to have(1).errors_on(:agency_id)
end
end
但它不起作用,这是一种废话。