From 52ecd67bbe5c28ab85bd2abb48509f14cdbd1f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Dund=C3=A1=C4=8Dek?= Date: Fri, 15 May 2015 18:12:41 +0200 Subject: [PATCH] Return an empty hash as metadata when Split is disabled --- lib/split/helper.rb | 3 ++- spec/helper_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/split/helper.rb b/lib/split/helper.rb index 3fc74a47..163280f3 100644 --- a/lib/split/helper.rb +++ b/lib/split/helper.rb @@ -29,7 +29,8 @@ def ab_test(metric_descriptor, control = nil, *alternatives) end if block_given? - yield(alternative, (trial.metadata if trial)) + metadata = trial ? trial.metadata : {} + yield(alternative, metadata) else alternative end diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb index 2846eb5b..564236d0 100755 --- a/spec/helper_spec.rb +++ b/spec/helper_spec.rb @@ -216,6 +216,17 @@ meta end).to eq('Meta1') end + + it 'should pass empty hash to helper block if library disabled' do + Split.configure do |config| + config.enabled = false + end + + expect(ab_test('my_experiment')).to eq 'one' + expect(ab_test('my_experiment') do |_, meta| + meta + end).to eq({}) + end end describe 'finished' do