Skip to content

Commit 03eab94

Browse files
eliotsykesandrew
authored andcommitted
Tweak RSpec instructions (#540)
1 parent 3fbf1be commit 03eab94

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

README.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,43 +161,39 @@ It is not required to send `SPLIT_DISABLE=false` to activate Split.
161161

162162

163163
### Rspec Helper
164-
To aid testing with RSpec, write `split_helper.rb` and call `use_ab_test(alternatives_by_experiment)` in your specs as instructed below:
164+
To aid testing with RSpec, write `spec/support/split_helper.rb` and call `use_ab_test(alternatives_by_experiment)` in your specs as instructed below:
165165

166166
```ruby
167-
# Recommended path for this file is 'spec/support/split_helper.rb'
167+
# Create a file with these contents at 'spec/support/split_helper.rb'
168+
# and ensure it is `require`d in your rails_helper.rb or spec_helper.rb
168169
module SplitHelper
170+
171+
# Force a specific experiment alternative to always be returned:
172+
# use_ab_test(signup_form: "single_page")
173+
#
174+
# Force alternatives for multiple experiments:
175+
# use_ab_test(signup_form: "single_page", pricing: "show_enterprise_prices")
176+
#
169177
def use_ab_test(alternatives_by_experiment)
170178
allow_any_instance_of(Split::Helper).to receive(:ab_test) do |_receiver, experiment|
171-
alternatives_by_experiment.fetch(experiment) { |key| raise "Unknown experiment '#{key}'" }
179+
alternatives_by_experiment.fetch(experiment) { |key| raise "Unknown experiment '#{key}'" }
172180
end
173181
end
174182
end
175-
```
176183

177-
Needs to ensure it `required` by rails_helper.rb or spec_helper.rb
178-
```ruby
179184
# Make the `use_ab_test` method available to all specs:
180185
RSpec.configure do |config|
181186
config.include SplitHelper
182187
end
183188
```
184189

185-
Example:
190+
Now you can call `use_ab_test(alternatives_by_experiment)` in your specs, for example:
186191
```ruby
187192
it "registers using experimental signup" do
188-
189193
use_ab_test experiment_name: "alternative_name"
190-
191194
post "/signups"
192-
193195
...
194196
end
195-
196-
# Force a specific experiment alternative to always be returned:
197-
# use_ab_test(signup_form: "single_page")
198-
#
199-
# Force alternatives for multiple experiments:
200-
# use_ab_test(signup_form: "single_page", pricing: "show_enterprise_prices")
201197
```
202198

203199

0 commit comments

Comments
 (0)