Project

randall

0.0
No commit activity in last 3 years
No release in over 3 years
Generate random instances of any classes.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.1.0

Runtime

>= 1.4.7
 Project Readme

Randall¶ ↑

*Randomly generates instances of any class*

Dependencies¶ ↑

Beautiful treetop is needed for parsing regular expressions, so we can generate random character strings matching a regexp.

Slim bacon is used for executing specs. You need not install bacon to use Randall.

Install¶ ↑

gem install randall

Randall uses Fiber, so can be used on Ruby 1.9 or JRuby only.

Tested on:

  • ruby 1.9.1 p378

  • jruby 1.5.0 with option –1.9

Examples¶ ↑

Canonical approach¶ ↑

Numbers¶ ↑

String¶ ↑

Array and Hash¶ ↑

Objects¶ ↑

Syntax sugars¶ ↑

Some methods are provided to specify the type and restrictions.

r = Randall
r.integers.less_than(100)  # Same as r.generate(Integer, :less_than => 100)
r.floats.gt(100) # => r.generate(Float, :greater_than => 100)
r.floats.clost_to(0)
r.integers.in_range(1..2)

For generating strings.

number = Randall.strings.that.match(/[0-9]+/)

Above example has the same effect as number = Randall.new(String, :like => /[0-9]+/).

Generate Arrays whose elements are generated by number.

Randall.arrays.of(number).size(100)

Generate Hashes whose keys are

Randall.hashes.from(number).to(String).size(10)

Some monkey patching¶ ↑

  • +Array#pick+ randomly pick an element from the receiver.

  • +Regexp#rand+ generates a String that matches the receiver.

Monkey patching is disabled by default. You must patch explicitly, by calling RandallMonkey.patch.

Limitations on Generating Strings for Regular Expressions¶ ↑

  • Anchors, except +^+ and +$+, are ignored.

  • +p{*}+ and +P{*}+ are not supported.

  • Unicode characters are not supported.

  • +(?*)+ extension is not supported.

  • Back-reference is not supported.

License¶ ↑

The MIT license.

Copyright (2010), Diego Che (chekenan@gmail.com)

  • randexp generates random data from a

Regular Expression. The +Array#pick+ is from here.

report bugs to the github issue tracker.