Ответ 1
С Rspec 2.13.0 я смог сделать
Foo.where(bar: 1, baz: 2).should exist
Edit:
Rspec теперь имеет синтаксис ожиданий:
expect(Foo.where(bar: 1, bax: 2)).to exist
Есть ли лучший способ проверить наличие записи в RSpec?
Foo.where(bar: 1, baz:2).count.should == 1
С Rspec 2.13.0 я смог сделать
Foo.where(bar: 1, baz: 2).should exist
Edit:
Rspec теперь имеет синтаксис ожиданий:
expect(Foo.where(bar: 1, bax: 2)).to exist
Использование синтаксиса ожидания:
expect(Foo.where(bar: 1, baz: 2)).not_to be_empty
expect(Foo.where(bar: 1, baz: 2)).to exist
Для rspec-rails > 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.exists?(bar: 1, baz: 2).should be_true
Foo.where(bar: 1, baz: 2).exists?.should be_true