brood
Brood allows you to generate test-fixture data from re-usable factories.
Installation
System:
gem install "brood"
Bundler:
source "https://rubygems.org"
group :test do
gem "brood"
end
Next run bundle install
to update your gem dependencies.
Usage
Example:
class Department
attr_accessor :id, :name, :users
end
class User
attr_accessor :id, :name, :department, :counter
end
Fabricator(:department) do
id { sequence(:id) }
name
end
Fabricator(:user) do
id { sequence(:id) }
name { Faker::Name.name }
department
end
@brood = Brood.new
gizmos = @brood.create([:department, :gizmos], {name: "Gizmos"})
@brood.create([:user, :bar], {id: 12, name: "Bar"})
@brood.create([:user, :baaz], {name: "Baaz"})
@brood.create([:user, :baar], {name: "Baar"}) do |user|
user.department = gizmos
end
gadgets = @brood.build([:department, :gadgets], {name: "Gadgets"})
foobar = @brood.build([:user, :foobar], {name: "Foobar"}) do |user|
user.department = gadgets
end
@brood.get([:user, :bar])
@brood.get([:user, :baaz])
@brood.get([:user, :foobar])
@brood.get([:bogus, :bar])
@brood.get([:user, :quux])
@brood.get([:user, :bar]) do |user|
counter = user.counter
sleep 0.0001
user.counter = counter + 1
end
See brood's own Minitest-based test suite for a more complete example.
Development
Commands
bundle exec rake
: run tests and lintbundle exec standardrb
: lintbundle exec yardoc
: generate YARD documentation
Dependencies
Inspiration
See the following article by Martin Fowler: https://www.martinfowler.com/bliki/ObjectMother.html
Author
Copyright
License
Apache-2.0