2012-12-07 28 views

Trả lời

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

sử dụng Foo.exists?(bar: 1, baz: 2).should be_true

28

Với Rspec 2.13.0, tôi đã có thể làm

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

Edit:

RSpec hiện có an expect syntax:

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

'mong đợi (Foo.find_by_bar (1)). Để be_present' khi bạn đang sử dụng công cụ tìm – Andrei

7

Sử dụng cú pháp mong đợi:

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

Đối rspec-ray> 3,0

Có một mô hình 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 
Các vấn đề liên quan