Configuration
For A/B testing in Rails there is a gem named vanity. At first we have to install the vanity gem by the command=> gem install vanity. After that we have to just configure the test.rb file under the “/environments” folder as follow…
config.after_initialize do require "vanity" Vanity.playground.test! end
Be careful this code must be written at the end of the file. Here we used Vanity.playground.test! for not accessing the redis for storing data. But if we want to access redis then we have to configure as follows…
Vanity.playground.redis = "::15" # Different DB Vanity.playground.redis.flushdb # Do this before running tests
Add a new controller for Vanity:
class VanityController < ApplicationController include Vanity::Rails::Dashboard end
Lets write a test code ===>
Now our A/B test file should be under the “experiments/” folder. Lets see a sample code
ab_test "Customer Message without Pricing" do description "Testing to see if messages without pricing increases number of signups." metrics :trial_activation end
Here the name of the metric parameter is same as the name of the file where our actual experiment is done under the “experiments/metrics/” directory. The following code is contained in the trial_activation.rb file.
metric "Signup for trial" do description "Measures how many people signed up to try our awesome service." model Account.in_trial end
Read more: http://labnotes.org/2009/11/19/vanity-experiment-driven-development-for-rails/#ixzz0jZMRkbJi