File tree Expand file tree Collapse file tree 4 files changed +36
-19
lines changed Expand file tree Collapse file tree 4 files changed +36
-19
lines changed Original file line number Diff line number Diff line change 11my_experiment :
2- - condition_b
3- - condition_c
2+ condition_b : 1
3+ condition_c : 1
44
55another_experiment :
6- - foo
7- - bar
6+ foo : 1
7+ bar : 1
88
99third_experiment :
10- - boo
10+ boo : 1
Original file line number Diff line number Diff 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
2930end
Original file line number Diff line number Diff line change 11module AbPanel
2- VERSION = "0.3.0 "
2+ VERSION = "0.3.1 "
33end
Original file line number Diff line number Diff line change 22
33describe 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
1935end
You can’t perform that action at this time.
0 commit comments