Sha256: 14d4aaaab340089b03678996c6a68861c93edf6d539f56b151732cfe20a69412
Contents?: true
Size: 1.72 KB
Versions: 2
Compression:
Stored size: 1.72 KB
Contents
require 'helper' describe Flipper::Gates::PercentageOfActors do let(:feature_name) { :search } subject { described_class.new } describe "#description" do context "when enabled" do it "returns text" do subject.description(22).should eq('22% of actors') end end context "when disabled" do it "returns disabled" do subject.description(0).should eq('disabled') end end end describe "#open?" do context "when compared against two features" do let(:percentage) { 0.05 } let(:percentage_as_integer) { percentage * 100 } let(:number_of_actors) { 100 } let(:actors) { (1..number_of_actors).map { |n| Struct.new(:flipper_id).new(n) } } let(:feature_one_enabled_actors) do gate = described_class.new actors.select { |actor| gate.open? actor, percentage_as_integer, feature_name: :name_one } end let(:feature_two_enabled_actors) do gate = described_class.new actors.select { |actor| gate.open? actor, percentage_as_integer, feature_name: :name_two } end it "does not enable both features for same set of actors" do feature_one_enabled_actors.should_not eq(feature_two_enabled_actors) end it "enables feature for accurate number of actors for each feature" do margin_of_error = 0.02 * number_of_actors # 2 percent margin of error expected_enabled_size = number_of_actors * percentage [ feature_one_enabled_actors.size, feature_two_enabled_actors.size, ].each do |actual_enabled_size| actual_enabled_size.should be_within(margin_of_error).of(expected_enabled_size) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
flipper-0.7.0.beta2 | spec/flipper/gates/percentage_of_actors_spec.rb |
flipper-0.7.0.beta1 | spec/flipper/gates/percentage_of_actors_spec.rb |