Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Rack::AB module for A/B testing #35

wants to merge 14 commits into


None yet
2 participants

Default settings assign users to one of two buckets, "a" and "b", and store the bucket name in a cookie called "rack_ab". If a bucket has not yet been assigned for a user, one is randomly chosen. The bucket name is made available to the app via the env object.

Basic usage looks like this:

use Rack::AB
# ...
if 'a' == env['rack.ab.bucket_name']
  body = 'content for bucket a'
  body = 'content for bucket b'
# ...
[200, {}, body]

Configuration options allow:

  • custom cookie name, e.g., "bucket_name" instead of "rack_ab"
  • custom bucket names, e.g. "control" and "fancy_bucket" instead of "a" and "b"
  • custom cookie parameters such as path, domain, and expires.

Custom configuration looks like this:

use Rack::AB, :bucket_names => ['control', 'new_feature']
# ...

Any and all feedback welcome.

Erik Eldridge added some commits Apr 6, 2011

Erik Eldridge Create AB testing middleware for Rack
Define basic functionality and initial spec tests
Erik Eldridge Simplify args passed to Rack::AB 54560f5
Erik Eldridge Correct assertion logic
Since Rack::AB can return 'a' or 'b' randomly, verify that
an array of correct response values includes the value we receive.
Erik Eldridge Write test to verify no cookie set if one exists
Rack::AB should only set a cookie if one has not been set before
Erik Eldridge Create test for custom cookie name ecab8e1
Erik Eldridge Update initialize to accept params hash
Simplify arg syntax for initializer by accepting a hash instead
of ordered args
Erik Eldridge Create test for custom possible values
Developers should be able to define custom values to
use in the cookie. Create a test to verify
Erik Eldridge Write test to verify cookie expiration setting 200765f
Erik Eldridge Rename possible_values to bucket_names
bucket_names is more self-descriptive.
Erik Eldridge Add Rack::AB to autoload 48afa95
Erik Eldridge Add bucket name to env obj, and comment code 009acc1
Erik Eldridge Add test for splitting traffic 8117831
Erik Eldridge Remove .gitignore from repo ad9e0b4
Erik Eldridge Add Rack::AB to readme ceb20d9

josh commented Apr 12, 2011

Sorry, but we aren't accepting any new middleware.

I'd suggest staring your own rack-ab project on github.

@josh josh closed this Apr 12, 2011

Thanks for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment