spec/flipper/feature_spec.rb in flipper-0.7.0.beta2 vs spec/flipper/feature_spec.rb in flipper-0.7.0.beta3

- old
+ new

@@ -95,12 +95,17 @@ it "returns easy to read string representation" do string = subject.inspect string.should include('Flipper::Feature') string.should include('name=:search') string.should include('state=:off') - string.should include('description="Disabled"') + string.should include('enabled_gate_names=[]') string.should include("adapter=#{subject.adapter.name.inspect}") + + subject.enable + string = subject.inspect + string.should include('state=:on') + string.should include('enabled_gate_names=[:boolean]') end end describe "instrumentation" do let(:instrumenter) { Flipper::Instrumenters::Memory.new } @@ -176,86 +181,96 @@ it "returns false for conditional?" do subject.conditional?.should be(false) end end - context "fully off" do + context "percentage of time set to 100" do before do - subject.disable + subject.enable_percentage_of_time 100 end - it "returns :off" do - subject.state.should be(:off) + it "returns :on" do + subject.state.should be(:on) end - it "returns false for on?" do - subject.on?.should be(false) + it "returns true for on?" do + subject.on?.should be(true) end - it "returns true for off?" do - subject.off?.should be(true) + it "returns false for off?" do + subject.off?.should be(false) end it "returns false for conditional?" do subject.conditional?.should be(false) end end - context "partially on" do + context "percentage of actors set to 100" do before do - subject.enable Flipper::Types::PercentageOfTime.new(5) + subject.enable_percentage_of_actors 100 end - it "returns :conditional" do - subject.state.should be(:conditional) + it "returns :on" do + subject.state.should be(:on) end - it "returns false for on?" do - subject.on?.should be(false) + it "returns true for on?" do + subject.on?.should be(true) end it "returns false for off?" do subject.off?.should be(false) end - it "returns true for conditional?" do - subject.conditional?.should be(true) + it "returns false for conditional?" do + subject.conditional?.should be(false) end end - end - describe "#description" do - context "fully on" do + context "fully off" do before do - subject.enable + subject.disable end - it "returns enabled" do - subject.description.should eq('Enabled') + it "returns :off" do + subject.state.should be(:off) end - end - context "fully off" do - before do - subject.disable + it "returns false for on?" do + subject.on?.should be(false) end - it "returns disabled" do - subject.description.should eq('Disabled') + it "returns true for off?" do + subject.off?.should be(true) end + + it "returns false for conditional?" do + subject.conditional?.should be(false) + end end context "partially on" do before do - actor = Struct.new(:flipper_id).new(5) subject.enable Flipper::Types::PercentageOfTime.new(5) - subject.enable actor end - it "returns text" do - subject.description.should eq('Enabled for actors ("5"), 5% of the time') + it "returns :conditional" do + subject.state.should be(:conditional) end + + it "returns false for on?" do + subject.on?.should be(false) + end + + it "returns false for off?" do + subject.off?.should be(false) + end + + it "returns true for conditional?" do + subject.conditional?.should be(true) + end end end describe "#enabled_groups" do context "when no groups enabled" do @@ -619,8 +634,41 @@ subject.enable_percentage_of_actors(percentage) subject.gate_values.percentage_of_actors.should be(56) subject.disable_percentage_of_actors subject.gate_values.percentage_of_actors.should be(0) end + end + end + + describe "#enabled/disabled_gates" do + before do + subject.enable_percentage_of_time 5 + subject.enable_percentage_of_actors 5 + end + + it "can return enabled gates" do + subject.enabled_gates.map(&:name).to_set.should eq(Set[ + :percentage_of_actors, + :percentage_of_time, + ]) + + subject.enabled_gate_names.to_set.should eq(Set[ + :percentage_of_actors, + :percentage_of_time, + ]) + end + + it "can return disabled gates" do + subject.disabled_gates.map(&:name).to_set.should eq(Set[ + :actor, + :boolean, + :group, + ]) + + subject.disabled_gate_names.to_set.should eq(Set[ + :actor, + :boolean, + :group, + ]) end end end