经过测试的代码:
context 'validations' do
let(:super_campaign){FactoryGirl.create(:super_campaign)}
context 'package' do
it "Package should be present" do
expect(super_campaign.package).to be_valid
end
end
end
我收到的错误如undefined method "valid?" for "possimus":String
答案 0 :(得分:2)
expect(super_campaign).to be_valid # AR object, not it's attribute
答案 1 :(得分:1)
您只能测试整个模型是否有效。但是,您可以测试package
属性是否有错误。
context 'validations' do
let(:super_campaign){FactoryGirl.create(:super_campaign)}
context 'package' do
it "Package should be present" do
expect(super_campaign).to be_valid
expect(super_campaign.errors[:package]).to be_nil
end
end
end