Skip to content

Commit 580e2f9

Browse files
author
Peter de Ruijter
committed
Merge pull request #7 from Springest/fix/empty_ab_file
Fixes #6
2 parents f6baa43 + c6087fc commit 580e2f9

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

example/config/ab_panel.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
my_experiment:
2-
- condition_b
3-
- condition_c
2+
condition_b: 1
3+
condition_c: 1
44

55
another_experiment:
6-
- foo
7-
- bar
6+
foo: 1
7+
bar: 1
88

99
third_experiment:
10-
- boo
10+
boo: 1

lib/ab_panel/config.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def initialize
77
end
88

99
def experiments
10+
return {} if !settings
1011
settings.keys.map(&:to_sym)
1112
end
1213

@@ -21,9 +22,9 @@ def weights(experiment)
2122
end
2223

2324
def settings
24-
@settings ||= YAML.load(
25-
ERB.new(File.read(File.join(Rails.root, 'config', 'ab_panel.yml'))).result)
26-
.symbolize_keys
25+
return @settings if defined?(@settings)
26+
results = YAML.load(ERB.new(File.read(File.join(Rails.root, 'config', 'ab_panel.yml'))).result)
27+
@settings = results ? results.symbolize_keys : nil
2728
end
2829
end
2930
end

lib/ab_panel/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module AbPanel
2-
VERSION = "0.3.0"
2+
VERSION = "0.3.1"
33
end

spec/ab_panel/config_spec.rb

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,34 @@
22

33
describe AbPanel::Config do
44
let(:config) { AbPanel::Config.new }
5-
before do
6-
AbPanel::Config.any_instance.stub(:settings) { { exp1: { scenario1: 25, scenario2: 75 } } }
7-
end
5+
context "config" do
6+
before do
7+
AbPanel::Config.any_instance.stub(:settings) { { exp1: { scenario1: 25, scenario2: 75 } } }
8+
end
89

9-
describe '.experiments' do
10-
subject { config.experiments }
11-
it { should =~ [:exp1] }
12-
end
10+
describe '.experiments' do
11+
subject { config.experiments }
12+
it { should =~ [:exp1] }
13+
end
1314

14-
describe '.weights' do
15-
subject { config.weights('exp1') }
15+
describe '.weights' do
16+
subject { config.weights('exp1') }
17+
18+
it { should =~ [75.0, 25.0] }
19+
end
20+
end
21+
context "empty config" do
22+
before do
23+
YAML.stub(:load) { false }
24+
end
25+
describe ".settings" do
26+
subject { config.settings }
27+
it { should eq nil }
28+
end
1629

17-
it { should =~ [75.0, 25.0] }
30+
describe ".experiments" do
31+
subject { config.experiments }
32+
it { should == {} }
33+
end
1834
end
1935
end

0 commit comments

Comments
 (0)