Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

jelly bird!

tree: c553327363

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENCE
Octocat-spinner-32 Rakefile
Octocat-spinner-32 jelly_bird.gemspec

Jelly Bird gem

Lightweight library for building objects in test/spec case's.


type gem install jelly_bird

or add to bundler ( test group )

"jelly_bird", :git => ""


assuming you have class called Dummy with two properties name and number you can create test factory this say:

      Dummy.define {{
        :name => /\w{3,8}/.gen,
        :number => /\d\d\d\d\d\d/.gen

to generate object in test just use .gen like this Dummy.gen to get generated object


class Dummy < Hash; end

Dummy.define {{
  :name => /\w{3,10}/.gen

10.times { puts Dummy.gen[:name] }

dummy = Dummy.gen
# dummy[:name] => random generated /\w{3,10}/ compilant word

other_dummy = Dummy.gen(:name => "dummy name")
# other_dummy[:name] => "dummy name"

custom factories

you can define custom factories, and generate object using .generate method with factory name like this.

Mummy.define {{
  :left  => /\w{3,10}/.gen,
  :right => /\w{3,10}/.gen

Mummy.define(:custom) {{
  :center => /\w{3,10}/.gen

mummy = Mummy.generate(:custom, :mumble => true)

in fact .gen is just calling generate with :default symbol.

generate with hook

user = User.gen {|user| }

doing this returns you object which received :save after generating

integration with rspec

touch a file with defines like factories.rb in spec folder and then require it inside of your spec_helper.rb. Then define all the factories like this.

User.define {{
  :first_name => /\w{3,9}/.gen,
  :last_name  => /\w{3,8}/.gen,
  :email      => /\w{3,8}@\w{3,8}\.com/.gen

Family.define {{
  :father      => User.gen,
  :mom         => User.gen,
  :kind        => User.gen,
  :family_name => /\w{3,8}/.gen

remember that if you wanna embbed one into another please don't specify them at random order :).

Now just use it in tests!


0.0.6 - Added ability for .gen and .generate to take blocks which receives object to make things aka save 0.0.5 - Fixed bugs 0.0.4 - Yanked version 0.0.1 -> 0.0.3 - Initial release

Powered by

It is powered by randexp gem and initial concept was based on dm-sweatshop syntax. Big thanks to this two projects.


Jakub Oboza,

Something went wrong with that request. Please try again.