Skip to content

Commit 10289b2

Browse files
vermaxikandrew
authored andcommitted
Improve README regarding rspec usage (#538)
1 parent 6bac1b9 commit 10289b2

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

README.md

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,35 +159,47 @@ In the event you want to disable all tests without having to know the individual
159159

160160
It is not required to send `SPLIT_DISABLE=false` to activate Split.
161161

162+
163+
### Rspec Helper
162164
To aid testing with RSpec, write `split_helper.rb` and call `use_ab_test(alternatives_by_experiment)` in your specs as instructed below:
163165

164166
```ruby
165-
# Recommended path for this file is 'spec/support/split_helper.rb', and you will need to ensure it
166-
# is `require`-d by rails_helper.rb or spec_helper.rb
167+
# Recommended path for this file is 'spec/support/split_helper.rb'
167168
module SplitHelper
168-
169-
# Usage:
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-
#
177169
def use_ab_test(alternatives_by_experiment)
178170
allow_any_instance_of(Split::Helper).to receive(:ab_test) do |_receiver, experiment|
179-
alternative =
180171
alternatives_by_experiment.fetch(experiment) { |key| raise "Unknown experiment '#{key}'" }
181172
end
182173
end
183174
end
175+
```
184176

177+
Needs to ensure it `required` by rails_helper.rb or spec_helper.rb
178+
```ruby
179+
# Make the `use_ab_test` method available to all specs:
185180
RSpec.configure do |config|
186-
# Make the `use_ab_test` method available to all specs:
187181
config.include SplitHelper
188182
end
189183
```
190184

185+
Example:
186+
```ruby
187+
it "registers using experimental signup" do
188+
189+
use_ab_test experiment_name: "alternative_name"
190+
191+
post "/signups"
192+
193+
...
194+
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")
201+
```
202+
191203

192204
### Starting experiments manually
193205

0 commit comments

Comments
 (0)