spec/flipper/gates/boolean_spec.rb in flipper-0.4.0 vs spec/flipper/gates/boolean_spec.rb in flipper-0.5.0
- old
+ new
@@ -1,42 +1,109 @@
require 'helper'
require 'flipper/instrumenters/memory'
describe Flipper::Gates::Boolean do
- let(:adapter) { double('Adapter', :read => nil) }
- let(:feature) { double('Feature', :name => :search, :adapter => adapter) }
let(:instrumenter) { Flipper::Instrumenters::Memory.new }
+ let(:feature_name) { :search }
subject {
- described_class.new(feature, :instrumenter => instrumenter)
+ described_class.new(feature_name, :instrumenter => instrumenter)
}
describe "#description" do
context "for enabled" do
- before do
- subject.stub(:enabled? => true)
- end
-
it "returns Enabled" do
- subject.description.should eq('Enabled')
+ subject.description(true).should eq('Enabled')
end
end
context "for disabled" do
- before do
- subject.stub(:enabled? => false)
+ it "returns Disabled" do
+ subject.description(false).should eq('Disabled')
end
+ end
+ end
- it "returns Disabled" do
- subject.description.should eq('Disabled')
+ describe "#enabled?" do
+ context "for true value" do
+ it "returns true" do
+ subject.enabled?(true).should be_true
end
end
+
+ context "for false value" do
+ it "returns false" do
+ subject.enabled?(false).should be_false
+ end
+ end
+
+ context "for nil value" do
+ it "returns false" do
+ subject.enabled?(nil).should be_false
+ end
+ end
+
+ context "for empty string value" do
+ it "returns false" do
+ subject.enabled?('').should be_false
+ end
+ end
+
+ context "for the string true value" do
+ it "returns true" do
+ subject.enabled?('true').should be_true
+ end
+ end
+
+ context "for the string false value" do
+ it "returns false" do
+ subject.enabled?('false').should be_false
+ end
+ end
end
+ describe "#open?" do
+ context "for true value" do
+ it "returns true" do
+ subject.open?(Object.new, true).should be_true
+ end
+ end
+
+ context "for false value" do
+ it "returns false" do
+ subject.open?(Object.new, false).should be_false
+ end
+ end
+
+ context "for nil value" do
+ it "returns false" do
+ subject.open?(Object.new, nil).should be_false
+ end
+ end
+
+ context "for string true value" do
+ it "returns true" do
+ subject.open?(Object.new, 'true').should be_true
+ end
+ end
+
+ context "for string false value" do
+ it "returns false" do
+ subject.open?(Object.new, 'false').should be_false
+ end
+ end
+
+ context "for an empty string value" do
+ it "returns false" do
+ subject.open?(Object.new, '').should be_false
+ end
+ end
+ end
+
describe "instrumentation" do
it "is recorded for open" do
thing = nil
- subject.open?(thing)
+ subject.open?(thing, false)
event = instrumenter.events.last
event.should_not be_nil
event.name.should eq('gate_operation.flipper')
event.payload.should eq({