Skip to content

Commit eb46487

Browse files
committed
Add specs for ExperimentStorage
1 parent c9b1c56 commit eb46487

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

spec/experiment_storage_spec.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
describe Split::ExperimentStorage do
6+
let(:experiment) do
7+
{
8+
resettable: "false",
9+
algorithm: "Split::Algorithms::WeightedSample",
10+
alternatives: [ "foo", "bar" ],
11+
goals: ["purchase", "refund"],
12+
metadata: {
13+
"foo" => { "text" => "Something bad" },
14+
"bar" => { "text" => "Something good" }
15+
}
16+
}
17+
end
18+
before do
19+
Split.configuration.experiments = {
20+
my_exp: experiment
21+
}
22+
end
23+
24+
context "ConfigStorage" do
25+
let(:config_store) { Split::ExperimentStorage::ConfigStorage.new("my_exp") }
26+
27+
it "loads an experiment from the configuration" do
28+
stored_data = config_store.load
29+
expect(stored_data).to match(experiment)
30+
end
31+
32+
it "checks if an experiment exists on the configuration" do
33+
expect(config_store.exists?).to be_truthy
34+
expect(Split::ExperimentStorage::ConfigStorage.new("whatever").exists?).to be_falsy
35+
end
36+
37+
it "memoizes data from the configuration by default" do
38+
expect(config_store).to receive(:load!).once.and_call_original
39+
config_store.load
40+
config_store.load
41+
end
42+
end
43+
44+
context "from Redis" do
45+
before { Split::ExperimentCatalog.find_or_create(:my_exp) }
46+
let(:config_store) { Split::ExperimentStorage::RedisStorage.new("my_exp") }
47+
48+
it "loads an experiment from the configuration" do
49+
stored_data = config_store.load
50+
stored_data[:alternatives].map! { |alternative| alternative.name }
51+
expect(stored_data).to match(experiment)
52+
end
53+
54+
it "checks if an experiment exists on the configuration" do
55+
expect(config_store.exists?).to be_truthy
56+
expect(Split::ExperimentStorage::ConfigStorage.new("whatever").exists?).to be_falsy
57+
end
58+
end
59+
end

0 commit comments

Comments
 (0)