2012-12-07 18 views

Odpowiedz

2
Foo.where(bar: 1, baz: 2).exists?.should be_true 
4

użycie Foo.exists?(bar: 1, baz: 2).should be_true

28

Z Rspec 2.13.0, udało mi się zrobić

Foo.where(bar: 1, baz: 2).should exist 

Edit:

rspec ma teraz an expect syntax:

expect(Foo.where(bar: 1, bax: 2)).to exist 
+6

'spodziewać (Foo.find_by_bar (1)). Być be_present' podczas korzystania z finders – Andrei

7

Korzystanie składnię oczekiwać:

expect(Foo.where(bar: 1, baz: 2)).not_to be_empty 
expect(Foo.where(bar: 1, baz: 2)).to exist 
7

Dla rspec szyn> 3,0

posiadania modelu blogu

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 
Powiązane problemy