flipper 0.6.3 → 0.7.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/Gemfile +10 -10
- data/Guardfile +2 -1
- data/README.md +54 -23
- data/Rakefile +1 -1
- data/examples/dsl.rb +2 -2
- data/examples/{percentage_of_random.rb → percentage_of_time.rb} +1 -1
- data/lib/flipper.rb +25 -12
- data/lib/flipper/dsl.rb +96 -8
- data/lib/flipper/feature.rb +216 -37
- data/lib/flipper/gate.rb +6 -38
- data/lib/flipper/gate_values.rb +42 -0
- data/lib/flipper/gates/actor.rb +11 -13
- data/lib/flipper/gates/boolean.rb +3 -12
- data/lib/flipper/gates/group.rb +14 -16
- data/lib/flipper/gates/percentage_of_actors.rb +12 -13
- data/lib/flipper/gates/{percentage_of_random.rb → percentage_of_time.rb} +8 -11
- data/lib/flipper/instrumentation/log_subscriber.rb +1 -1
- data/lib/flipper/instrumentation/subscriber.rb +1 -1
- data/lib/flipper/spec/shared_adapter_specs.rb +16 -16
- data/lib/flipper/type.rb +1 -1
- data/lib/flipper/typecast.rb +44 -0
- data/lib/flipper/types/actor.rb +2 -5
- data/lib/flipper/types/group.rb +6 -0
- data/lib/flipper/types/percentage.rb +7 -1
- data/lib/flipper/types/{percentage_of_random.rb → percentage_of_time.rb} +1 -1
- data/lib/flipper/version.rb +1 -1
- data/script/bootstrap +21 -0
- data/script/guard +15 -0
- data/script/release +15 -0
- data/script/test +30 -0
- data/spec/flipper/dsl_spec.rb +67 -8
- data/spec/flipper/feature_spec.rb +424 -12
- data/spec/flipper/gate_spec.rb +1 -20
- data/spec/flipper/gate_values_spec.rb +134 -0
- data/spec/flipper/gates/actor_spec.rb +1 -21
- data/spec/flipper/gates/boolean_spec.rb +3 -71
- data/spec/flipper/gates/group_spec.rb +3 -23
- data/spec/flipper/gates/percentage_of_actors_spec.rb +5 -26
- data/spec/flipper/gates/percentage_of_time_spec.rb +23 -0
- data/spec/flipper/middleware/memoizer_spec.rb +1 -2
- data/spec/flipper/typecast_spec.rb +63 -0
- data/spec/flipper/types/group_spec.rb +21 -1
- data/spec/flipper/types/percentage_of_time_spec.rb +6 -0
- data/spec/flipper/types/percentage_spec.rb +20 -0
- data/spec/flipper_spec.rb +31 -9
- data/spec/helper.rb +1 -3
- data/spec/integration_spec.rb +22 -22
- metadata +21 -11
- data/spec/flipper/gates/percentage_of_random_spec.rb +0 -46
- data/spec/flipper/types/percentage_of_random_spec.rb +0 -6
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'flipper/typecast'
|
3
|
+
|
4
|
+
describe Flipper::Typecast do
|
5
|
+
{
|
6
|
+
nil => false,
|
7
|
+
"" => false,
|
8
|
+
0 => false,
|
9
|
+
1 => true,
|
10
|
+
"0" => false,
|
11
|
+
"1" => true,
|
12
|
+
true => true,
|
13
|
+
false => false,
|
14
|
+
"true" => true,
|
15
|
+
"false" => false,
|
16
|
+
}.each do |value, expected|
|
17
|
+
context "#to_boolean for #{value.inspect}" do
|
18
|
+
it "returns #{expected}" do
|
19
|
+
described_class.to_boolean(value).should be(expected)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
{
|
25
|
+
nil => 0,
|
26
|
+
"" => 0,
|
27
|
+
0 => 0,
|
28
|
+
1 => 1,
|
29
|
+
"1" => 1,
|
30
|
+
"99" => 99,
|
31
|
+
}.each do |value, expected|
|
32
|
+
context "#to_integer for #{value.inspect}" do
|
33
|
+
it "returns #{expected}" do
|
34
|
+
described_class.to_integer(value).should be(expected)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
{
|
40
|
+
nil => Set.new,
|
41
|
+
"" => Set.new,
|
42
|
+
Set.new([1, 2]) => Set.new([1, 2]),
|
43
|
+
[1, 2] => Set.new([1, 2])
|
44
|
+
}.each do |value, expected|
|
45
|
+
context "#to_set for #{value.inspect}" do
|
46
|
+
it "returns #{expected}" do
|
47
|
+
described_class.to_set(value).should eq(expected)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "raises argument error for integer value that cannot be converted to an integer" do
|
53
|
+
expect {
|
54
|
+
described_class.to_integer(["asdf"])
|
55
|
+
}.to raise_error(ArgumentError, %Q(["asdf"] cannot be converted to an integer))
|
56
|
+
end
|
57
|
+
|
58
|
+
it "raises argument error for set value that cannot be converted to a set" do
|
59
|
+
expect {
|
60
|
+
described_class.to_set("asdf")
|
61
|
+
}.to raise_error(ArgumentError, %Q("asdf" cannot be converted to a set))
|
62
|
+
end
|
63
|
+
end
|
@@ -3,7 +3,27 @@ require 'flipper/types/group'
|
|
3
3
|
|
4
4
|
describe Flipper::Types::Group do
|
5
5
|
subject do
|
6
|
-
Flipper
|
6
|
+
Flipper.register(:admins) { |actor| actor.admin? }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".wrap" do
|
10
|
+
context "with group instance" do
|
11
|
+
it "returns group instance" do
|
12
|
+
described_class.wrap(subject).should eq(subject)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "with Symbol group name" do
|
17
|
+
it "returns group instance" do
|
18
|
+
described_class.wrap(subject.name).should eq(subject)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with String group name" do
|
23
|
+
it "returns group instance" do
|
24
|
+
described_class.wrap(subject.name.to_s).should eq(subject)
|
25
|
+
end
|
26
|
+
end
|
7
27
|
end
|
8
28
|
|
9
29
|
it "initializes with name" do
|
@@ -7,6 +7,26 @@ describe Flipper::Types::Percentage do
|
|
7
7
|
}
|
8
8
|
it_should_behave_like 'a percentage'
|
9
9
|
|
10
|
+
describe ".wrap" do
|
11
|
+
context "with percentage instance" do
|
12
|
+
it "returns percentage instance" do
|
13
|
+
described_class.wrap(subject).should eq(subject)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with Integer" do
|
18
|
+
it "returns percentage instance" do
|
19
|
+
described_class.wrap(subject.value).should eq(subject)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with String" do
|
24
|
+
it "returns percentage instance" do
|
25
|
+
described_class.wrap(subject.value.to_s).should eq(subject)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
10
30
|
describe "#eql?" do
|
11
31
|
it "returns true for same class and value" do
|
12
32
|
subject.eql?(described_class.new(subject.value)).should eq(true)
|
data/spec/flipper_spec.rb
CHANGED
@@ -19,31 +19,31 @@ describe Flipper do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe ".
|
22
|
+
describe ".groups_registry" do
|
23
23
|
it "returns a registry instance" do
|
24
|
-
Flipper.
|
24
|
+
Flipper.groups_registry.should be_instance_of(Flipper::Registry)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe ".
|
29
|
-
it "sets
|
28
|
+
describe ".groups_registry=" do
|
29
|
+
it "sets groups_registry registry" do
|
30
30
|
registry = Flipper::Registry.new
|
31
|
-
Flipper.
|
32
|
-
Flipper.instance_variable_get("@
|
31
|
+
Flipper.groups_registry = registry
|
32
|
+
Flipper.instance_variable_get("@groups_registry").should eq(registry)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
describe ".register" do
|
37
37
|
it "adds a group to the group_registry" do
|
38
38
|
registry = Flipper::Registry.new
|
39
|
-
Flipper.
|
39
|
+
Flipper.groups_registry = registry
|
40
40
|
group = Flipper.register(:admins) { |actor| actor.admin? }
|
41
41
|
registry.get(:admins).should eq(group)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "adds a group to the group_registry for string name" do
|
45
45
|
registry = Flipper::Registry.new
|
46
|
-
Flipper.
|
46
|
+
Flipper.groups_registry = registry
|
47
47
|
group = Flipper.register('admins') { |actor| actor.admin? }
|
48
48
|
registry.get(:admins).should eq(group)
|
49
49
|
end
|
@@ -59,7 +59,7 @@ describe Flipper do
|
|
59
59
|
|
60
60
|
describe ".unregister_groups" do
|
61
61
|
it "clear group registry" do
|
62
|
-
Flipper.
|
62
|
+
Flipper.groups_registry.should_receive(:clear)
|
63
63
|
Flipper.unregister_groups
|
64
64
|
end
|
65
65
|
end
|
@@ -87,4 +87,26 @@ describe Flipper do
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
90
|
+
|
91
|
+
describe ".groups" do
|
92
|
+
it "returns array of group instances" do
|
93
|
+
admins = Flipper.register(:admins) { |actor| actor.admin? }
|
94
|
+
preview_features = Flipper.register(:preview_features) { |actor| actor.preview_features? }
|
95
|
+
Flipper.groups.should eq(Set[
|
96
|
+
admins,
|
97
|
+
preview_features,
|
98
|
+
])
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe ".group_names" do
|
103
|
+
it "returns array of group names" do
|
104
|
+
Flipper.register(:admins) { |actor| actor.admin? }
|
105
|
+
Flipper.register(:preview_features) { |actor| actor.preview_features? }
|
106
|
+
Flipper.group_names.should eq(Set[
|
107
|
+
:admins,
|
108
|
+
:preview_features,
|
109
|
+
])
|
110
|
+
end
|
111
|
+
end
|
90
112
|
end
|
data/spec/helper.rb
CHANGED
@@ -18,9 +18,7 @@ require 'flipper'
|
|
18
18
|
Dir[root_path.join("spec/support/**/*.rb")].each { |f| require f }
|
19
19
|
|
20
20
|
RSpec.configure do |config|
|
21
|
-
config.
|
22
|
-
|
23
|
-
config.filter_run :focused => true
|
21
|
+
config.filter_run :focus => true
|
24
22
|
config.alias_example_to :fit, :focused => true
|
25
23
|
config.alias_example_to :xit, :pending => true
|
26
24
|
config.run_all_when_everything_filtered = true
|
data/spec/integration_spec.rb
CHANGED
@@ -3,9 +3,7 @@ require 'flipper/feature'
|
|
3
3
|
require 'flipper/adapters/memory'
|
4
4
|
|
5
5
|
describe Flipper do
|
6
|
-
let(:
|
7
|
-
let(:adapter) { Flipper::Adapters::Memory.new(source) }
|
8
|
-
|
6
|
+
let(:adapter) { Flipper::Adapters::Memory.new }
|
9
7
|
let(:flipper) { Flipper.new(adapter) }
|
10
8
|
let(:feature) { flipper[:search] }
|
11
9
|
|
@@ -21,7 +19,7 @@ describe Flipper do
|
|
21
19
|
let(:clooney) { actor_class.new(10) }
|
22
20
|
|
23
21
|
let(:five_percent_of_actors) { flipper.actors(5) }
|
24
|
-
let(:
|
22
|
+
let(:five_percent_of_time) { flipper.time(5) }
|
25
23
|
|
26
24
|
before do
|
27
25
|
Flipper.register(:admins) { |thing| thing.admin? }
|
@@ -126,10 +124,10 @@ describe Flipper do
|
|
126
124
|
end
|
127
125
|
end
|
128
126
|
|
129
|
-
context "with a percentage of
|
127
|
+
context "with a percentage of time" do
|
130
128
|
before do
|
131
|
-
@gate = feature.gate(:
|
132
|
-
@result = feature.enable(
|
129
|
+
@gate = feature.gate(:percentage_of_time)
|
130
|
+
@result = feature.enable(five_percent_of_time)
|
133
131
|
end
|
134
132
|
|
135
133
|
it "returns true" do
|
@@ -164,19 +162,19 @@ describe Flipper do
|
|
164
162
|
describe "#disable" do
|
165
163
|
context "with no arguments" do
|
166
164
|
before do
|
167
|
-
# ensures that
|
168
|
-
@gate = feature.gate(:
|
165
|
+
# ensures that time gate is stubbed with result that would be true for pitt
|
166
|
+
@gate = feature.gate(:percentage_of_time)
|
169
167
|
@gate.stub(:rand => 0.04)
|
170
168
|
|
171
169
|
feature.enable admin_group
|
172
170
|
feature.enable pitt
|
173
171
|
feature.enable five_percent_of_actors
|
174
|
-
feature.enable
|
172
|
+
feature.enable five_percent_of_time
|
175
173
|
@result = feature.disable
|
176
174
|
end
|
177
175
|
|
178
176
|
it "returns true" do
|
179
|
-
@result.should
|
177
|
+
@result.should be(true)
|
180
178
|
end
|
181
179
|
|
182
180
|
it "disables feature" do
|
@@ -200,7 +198,7 @@ describe Flipper do
|
|
200
198
|
enabled.should be(0)
|
201
199
|
end
|
202
200
|
|
203
|
-
it "disables percentage of
|
201
|
+
it "disables percentage of time" do
|
204
202
|
feature.enabled?(pitt).should eq(false)
|
205
203
|
end
|
206
204
|
|
@@ -290,8 +288,8 @@ describe Flipper do
|
|
290
288
|
|
291
289
|
context "with a percentage of time" do
|
292
290
|
before do
|
293
|
-
@gate = feature.gate(:
|
294
|
-
@result = feature.disable(flipper.
|
291
|
+
@gate = feature.gate(:percentage_of_time)
|
292
|
+
@result = feature.disable(flipper.time(0))
|
295
293
|
end
|
296
294
|
|
297
295
|
it "returns true" do
|
@@ -379,13 +377,14 @@ describe Flipper do
|
|
379
377
|
end
|
380
378
|
end
|
381
379
|
|
382
|
-
context "
|
380
|
+
context "for enabled percentage of time" do
|
383
381
|
before do
|
384
|
-
# ensure percentage of
|
385
|
-
|
382
|
+
# ensure percentage of time returns percentage that makes five percent
|
383
|
+
# of time true
|
384
|
+
@gate = feature.gate(:percentage_of_time)
|
386
385
|
@gate.stub(:rand => 0.04)
|
387
386
|
|
388
|
-
feature.enable
|
387
|
+
feature.enable five_percent_of_time
|
389
388
|
end
|
390
389
|
|
391
390
|
it "returns true" do
|
@@ -396,13 +395,14 @@ describe Flipper do
|
|
396
395
|
end
|
397
396
|
end
|
398
397
|
|
399
|
-
context "
|
398
|
+
context "for not enabled percentage of time" do
|
400
399
|
before do
|
401
|
-
# ensure percentage of
|
402
|
-
|
400
|
+
# ensure percentage of time returns percentage that makes five percent
|
401
|
+
# of time false
|
402
|
+
@gate = feature.gate(:percentage_of_time)
|
403
403
|
@gate.stub(:rand => 0.10)
|
404
404
|
|
405
|
-
feature.enable
|
405
|
+
feature.enable five_percent_of_time
|
406
406
|
end
|
407
407
|
|
408
408
|
it "returns false" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Feature flipper for any adapter
|
14
14
|
email:
|
@@ -33,7 +33,7 @@ files:
|
|
33
33
|
- examples/individual_actor.rb
|
34
34
|
- examples/instrumentation.rb
|
35
35
|
- examples/percentage_of_actors.rb
|
36
|
-
- examples/
|
36
|
+
- examples/percentage_of_time.rb
|
37
37
|
- flipper.gemspec
|
38
38
|
- lib/flipper.rb
|
39
39
|
- lib/flipper/adapter.rb
|
@@ -47,11 +47,12 @@ files:
|
|
47
47
|
- lib/flipper/errors.rb
|
48
48
|
- lib/flipper/feature.rb
|
49
49
|
- lib/flipper/gate.rb
|
50
|
+
- lib/flipper/gate_values.rb
|
50
51
|
- lib/flipper/gates/actor.rb
|
51
52
|
- lib/flipper/gates/boolean.rb
|
52
53
|
- lib/flipper/gates/group.rb
|
53
54
|
- lib/flipper/gates/percentage_of_actors.rb
|
54
|
-
- lib/flipper/gates/
|
55
|
+
- lib/flipper/gates/percentage_of_time.rb
|
55
56
|
- lib/flipper/instrumentation/log_subscriber.rb
|
56
57
|
- lib/flipper/instrumentation/metriks.rb
|
57
58
|
- lib/flipper/instrumentation/metriks_subscriber.rb
|
@@ -64,13 +65,18 @@ files:
|
|
64
65
|
- lib/flipper/registry.rb
|
65
66
|
- lib/flipper/spec/shared_adapter_specs.rb
|
66
67
|
- lib/flipper/type.rb
|
68
|
+
- lib/flipper/typecast.rb
|
67
69
|
- lib/flipper/types/actor.rb
|
68
70
|
- lib/flipper/types/boolean.rb
|
69
71
|
- lib/flipper/types/group.rb
|
70
72
|
- lib/flipper/types/percentage.rb
|
71
73
|
- lib/flipper/types/percentage_of_actors.rb
|
72
|
-
- lib/flipper/types/
|
74
|
+
- lib/flipper/types/percentage_of_time.rb
|
73
75
|
- lib/flipper/version.rb
|
76
|
+
- script/bootstrap
|
77
|
+
- script/guard
|
78
|
+
- script/release
|
79
|
+
- script/test
|
74
80
|
- spec/flipper/adapters/instrumented_spec.rb
|
75
81
|
- spec/flipper/adapters/memoizable_spec.rb
|
76
82
|
- spec/flipper/adapters/memory_spec.rb
|
@@ -78,11 +84,12 @@ files:
|
|
78
84
|
- spec/flipper/dsl_spec.rb
|
79
85
|
- spec/flipper/feature_spec.rb
|
80
86
|
- spec/flipper/gate_spec.rb
|
87
|
+
- spec/flipper/gate_values_spec.rb
|
81
88
|
- spec/flipper/gates/actor_spec.rb
|
82
89
|
- spec/flipper/gates/boolean_spec.rb
|
83
90
|
- spec/flipper/gates/group_spec.rb
|
84
91
|
- spec/flipper/gates/percentage_of_actors_spec.rb
|
85
|
-
- spec/flipper/gates/
|
92
|
+
- spec/flipper/gates/percentage_of_time_spec.rb
|
86
93
|
- spec/flipper/instrumentation/log_subscriber_spec.rb
|
87
94
|
- spec/flipper/instrumentation/metriks_subscriber_spec.rb
|
88
95
|
- spec/flipper/instrumentation/statsd_subscriber_spec.rb
|
@@ -90,11 +97,12 @@ files:
|
|
90
97
|
- spec/flipper/instrumenters/noop_spec.rb
|
91
98
|
- spec/flipper/middleware/memoizer_spec.rb
|
92
99
|
- spec/flipper/registry_spec.rb
|
100
|
+
- spec/flipper/typecast_spec.rb
|
93
101
|
- spec/flipper/types/actor_spec.rb
|
94
102
|
- spec/flipper/types/boolean_spec.rb
|
95
103
|
- spec/flipper/types/group_spec.rb
|
96
104
|
- spec/flipper/types/percentage_of_actors_spec.rb
|
97
|
-
- spec/flipper/types/
|
105
|
+
- spec/flipper/types/percentage_of_time_spec.rb
|
98
106
|
- spec/flipper/types/percentage_spec.rb
|
99
107
|
- spec/flipper_spec.rb
|
100
108
|
- spec/helper.rb
|
@@ -114,9 +122,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
122
|
version: '0'
|
115
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
124
|
requirements:
|
117
|
-
- - "
|
125
|
+
- - ">"
|
118
126
|
- !ruby/object:Gem::Version
|
119
|
-
version:
|
127
|
+
version: 1.3.1
|
120
128
|
requirements: []
|
121
129
|
rubyforge_project:
|
122
130
|
rubygems_version: 2.2.2
|
@@ -131,11 +139,12 @@ test_files:
|
|
131
139
|
- spec/flipper/dsl_spec.rb
|
132
140
|
- spec/flipper/feature_spec.rb
|
133
141
|
- spec/flipper/gate_spec.rb
|
142
|
+
- spec/flipper/gate_values_spec.rb
|
134
143
|
- spec/flipper/gates/actor_spec.rb
|
135
144
|
- spec/flipper/gates/boolean_spec.rb
|
136
145
|
- spec/flipper/gates/group_spec.rb
|
137
146
|
- spec/flipper/gates/percentage_of_actors_spec.rb
|
138
|
-
- spec/flipper/gates/
|
147
|
+
- spec/flipper/gates/percentage_of_time_spec.rb
|
139
148
|
- spec/flipper/instrumentation/log_subscriber_spec.rb
|
140
149
|
- spec/flipper/instrumentation/metriks_subscriber_spec.rb
|
141
150
|
- spec/flipper/instrumentation/statsd_subscriber_spec.rb
|
@@ -143,11 +152,12 @@ test_files:
|
|
143
152
|
- spec/flipper/instrumenters/noop_spec.rb
|
144
153
|
- spec/flipper/middleware/memoizer_spec.rb
|
145
154
|
- spec/flipper/registry_spec.rb
|
155
|
+
- spec/flipper/typecast_spec.rb
|
146
156
|
- spec/flipper/types/actor_spec.rb
|
147
157
|
- spec/flipper/types/boolean_spec.rb
|
148
158
|
- spec/flipper/types/group_spec.rb
|
149
159
|
- spec/flipper/types/percentage_of_actors_spec.rb
|
150
|
-
- spec/flipper/types/
|
160
|
+
- spec/flipper/types/percentage_of_time_spec.rb
|
151
161
|
- spec/flipper/types/percentage_spec.rb
|
152
162
|
- spec/flipper_spec.rb
|
153
163
|
- spec/helper.rb
|