2012-12-07 2 views

Répondre

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

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

28

Avec Rspec 2.13.0, j'ai pu faire

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

Edit:

Rspec a maintenant an expect syntax:

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

'expect (Foo.find_by_bar (1)). À be_present' lorsque vous utilisez des finders – Andrei

7

Utilisation de la s'attendre à la syntaxe:

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

Pour rspec-rails> 3.0

Avoir un modèle de blog,

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 
Questions connexes