Extensions
Fabrication
Paul Elliott's
Fabrication gem is
a slick object generation library. It support's Mongoid out of the box and
provides a nice syntax for creating objects with ease for testing.
Fabricator(:person) do
title "Grand Poobah"
addresses(:count => 2) do |address, i|
Fabricate(:address, :streeet => "#{i} Bond St.")
end
end
mongoid-rspec
Evan Sagge's mongoid-rspec
provides RSpec matchers for Mongoid. Includes matchers for associations,
options, validations, and fields.
describe Person do
it { should reference_one :account }
it { should reference_many :posts }
it { should be_referenced_in :organization }
it { should validate_presence_of(:name) }
it { should have_field(:age).of_type(Integer) }
end
describe Address do
it { should be_embedded_in(:person).as_inverse_of(:addresses) }
end
Remarkable
Brian Cardarella's
remarkable-mongoid
gem provides a nice addition of RSpec matchers for Mongoid. It contains
the matchers shown below, plus all validation matchers from
Remarkable::ActiveModel.
describe Person do
it { should reference_one :account }
it { should reference_many :posts }
it { should be_referenced_in :organization }
it { should embed_one :name }
it { should embed_many :addresses }
it { should be_embedded_in :group }
it { should validate_uniqueness_of :dob }
end
Riot
The Riot-Mongoid
gem provides a nice addition of riot assertions for Mongoid. It contains
assertions for fields, keys, associations, and validations.
context "Person Model" do
setup { Person.new }
asserts_topic.has_field :title, :type => String
asserts_topic.has_association :references_one, :account
asserts_topic.has_association :embeds_many, :addresses
asserts_topic.has_validation :validates_presence_of, :title
end