RSpec / RSpec Rails / Docs / Model specs
This page comes from RSpec Rails 2.99.0. It is not part of the 6.0.1 docs. See the latest RSpec Rails docs.
records
Scenario: asserting number of records
- Given a file named "
spec/models/widget_spec.rb" with:rubyrequire "spec_helper" describe Widget do it "has no widgets in the database" do expect(Widget).to have(:no).records expect(Widget).to have(0).records end it "has one record" do Widget.create!(:name => "Cog") expect(Widget).to have(1).record end it "counts only records that match a query" do Widget.create!(:name => "Cog") expect(Widget.where(:name => "Cog")).to have(1).record expect(Widget.where(:name => "Wheel")).to have(0).records end end - When I run `rspec spec/models/widget_spec.rb`
- Then the examples should all pass
Source: features/model_specs/records.feature at v2.99.0, RSpec Rails (MIT license).