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)
Links¶ ↑
-
randexp generates random data from a
Regular Expression. The +Array#pick+ is from here.
-
Source Repository. You can also
report bugs to the github issue tracker.