Welcome to the assert_statistically page at RubyForge

Introduction
Project Page
Copyright
Note
Installation
Tests
Usage
Source
Bugs
Contact

Introduction

assert_statistically is an addition to Test::Unit::TestCase that works like assert_block, allowing you to run a given block multiple times and determine what constitutes "passing."

Project Page

http://rubyforge.org/projects/statistically/

Copyright

assert_statistically is copyright 2007,2008 by Zach Holt. It is released under the MIT license. See the MIT-LICENSE file in your distribution for more information.

Note

Please note that 0.2.0 is incompatible with 0.1.1. Notably, there is no longer a :sleep option.

Installation

gem install assert_statistically or sudo gem install assert_statistically

Tests

gem check -t assert_statistically
or ruby /...path_to_gem.../test/all_tests.rb

Usage

Once you've installed the gem, you can do the following:
require 'rubygems'
require 'assert_statistically'
The code below will execute the block 10 times, passing only if the block passes (as defined by assert_block) no fewer than 3 times and no more than 6 times.
assert_statistically( :of => 10, :min => 3, :max => 6 ) do
	the_test_code
end
Note that assert_statistically short circuits by default--if it determines that it cannot fail or cannot pass after any certain point, it will perform no more iterations. To override this behavior, pass in
:short_circuit => false
To set the error message, do something like the following:
assert_statistically( :message => 'Test %d failed', :of => 10 ) do
	the_test_code
end
Note that the final error message will be composed of messages from each failed test. Also note that the message string will be formatted with the index of the failed test. You can leave out the %d, but if you include it, it will be replaced with the appropriate value.
assert_statistically( :of => 10, :after => lambda{ |i,s| sleep 0.5 } ) do
	the_test_code
end
The above snippet will run the block 10 times, sleeping half a second between each run. You can pass in :before and :after Proc objects, which will be run before and after the test Proc. Each can take two parameters, the number of completed tests, followed by the number of successful tests. Note that "completed tests" in the :before Proc will be one smaller than "completed tests" in the :after Proc.

Similarly, the main test block can optionally take the iteration number and the number of successful iterations as parameters.

Source

You can browse the source via your web browser, or svn checkout svn://rubyforge.org/var/svn/statistically/trunk

Bugs

Please submit bugs here.

Contact

Please feel free to use the forums!