README.md in govuk_ab_testing-2.4.0 vs README.md in govuk_ab_testing-2.4.1
- old
+ new
@@ -48,33 +48,48 @@
```ruby
# app/controllers/party_controller.rb
class PartyController < ApplicationController
def show
- ab_test = GovukAbTesting::AbTest.new("your_ab_test_name", dimension: 300)
+ ab_test = GovukAbTesting::AbTest.new(
+ "your_ab_test_name",
+ dimension: 300,
+ allowed_variants: ['NoChange', 'LongTitle', 'ShortTitle'],
+ control_variant: 'NoChange'
+ )
@requested_variant = ab_test.requested_variant(request.headers)
@requested_variant.configure_response(response)
- if @requested_variant.variant?('B')
- render "new_show_template_to_be_tested"
+ case true
+ when @requested_variant.variant?('LongTitle')
+ render "show_template_with_long_title"
+ when @requested_variant.variant?('ShortTitle')
+ render "show_template_with_short_title"
else
render "show"
end
end
end
```
-Add this to your layouts, so that we have a meta tag that can be picked up
+In this example, we are running a multivariate test with 3 options being
+tested: the existing version (control), and two title changes. The minimum
+number of variants in any test should be two.
+
+Then, add this to your layouts, so that we have a meta tag that can be picked up
by the extension and analytics.
```html
<!-- application.html.erb -->
<head>
<%= @requested_variant.analytics_meta_tag.html_safe %>
</head>
```
+The analytics meta tag will include the allowed variants so the extension knows
+which variants to suggest the user.
+
#### Test helpers
##### Minitest
The most common usage of an A/B test is to serve two different variants of the
@@ -155,11 +170,11 @@
```
##### RSpec
It is also possible to use `with_variant` and all the individual setup and
-assertions steps in RSpec tests. Here is an example of a spec file:
+assertions steps in RSpec tests. Here is an example of a Capybara feature file:
```ruby
# spec/features/ab_testing_spec.rb
feature "Viewing a page with an A/B test" do
include GovukAbTesting::RspecHelpers
@@ -173,20 +188,32 @@
end
end
end
```
+And here is an RSpec controller test:
+
+```ruby
+# spec/controllers/some_controller_spec.rb
+describe SomeController, type :controller do
+ include GovukAbTesting::RspecHelpers
+
+ # RSpec doesn't render views for controller specs by default
+ render_views
+
+ it "should render the B version of the page" do
+ with_variant your_ab_test_name: 'B' do
+ get :index
+ end
+ end
+end
+```
+
As with the `minitest` version, you can also pass in the following options to
`with_variant`:
- `assert_meta_tag: false`
- `dimension: <number>`
-
-### Current limitations
-
-This library assumes we are only using one A/B test per page. The acceptance
-test classes look for only one analytics' meta tag and will fail in the presence
-of more than one.
### Running the test suite
`bundle exec rake`