में रिकॉर्ड के अस्तित्व की सुंदरता की जांच कैसे करें आरएसपीईसी में रिकॉर्ड के अस्तित्व की जांच करने का कोई बेहतर तरीका है?आरएसपीसी
Foo.where(bar: 1, baz:2).count.should == 1
में रिकॉर्ड के अस्तित्व की सुंदरता की जांच कैसे करें आरएसपीईसी में रिकॉर्ड के अस्तित्व की जांच करने का कोई बेहतर तरीका है?आरएसपीसी
Foo.where(bar: 1, baz:2).count.should == 1
Foo.where(bar: 1, baz: 2).exists?.should be_true
उपयोग Foo.exists?(bar: 1, baz: 2).should be_true
Rspec 2.13.0 के साथ, मैं ऐसा करने में सक्षम था
Foo.where(bar: 1, baz: 2).should exist
संपादित करें:
Rspec अब an expect syntax:
expect(Foo.where(bar: 1, bax: 2)).to exist
'उम्मीदवार (Foo.find_by_bar (1))। Be_present' जब आप खोजकर्ताओं का उपयोग कर रहे हों – Andrei
उम्मीद वाक्य रचना का उपयोग करना:
expect(Foo.where(bar: 1, baz: 2)).not_to be_empty
expect(Foo.where(bar: 1, baz: 2)).to exist
rspec-रेल> 3.0
एक ब्लॉग मॉडल होने के लिए,
describe 'POST #create' do
it "creates a post" do
post :create, :blog => { title: "blog title"}
#returns true if the post was successfully added
expect(Blog.where(title: "blog title")).to be_present
end
end
तुम कोशिश कर सकते हैं ' Foo.where (बार: 1, बाज़: 2)। Should_not be_empty'? – Dogbert