flipper 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +4 -0
  3. data/Gemfile +1 -1
  4. data/docs/Adapters.md +2 -1
  5. data/examples/enabled_for_actor.rb +43 -0
  6. data/lib/flipper/spec/shared_adapter_specs.rb +71 -71
  7. data/lib/flipper/version.rb +1 -1
  8. data/spec/flipper/adapters/instrumented_spec.rb +44 -44
  9. data/spec/flipper/adapters/memoizable_spec.rb +21 -21
  10. data/spec/flipper/adapters/memory_spec.rb +1 -1
  11. data/spec/flipper/adapters/operation_logger_spec.rb +11 -11
  12. data/spec/flipper/adapters/pstore_spec.rb +2 -2
  13. data/spec/flipper/dsl_spec.rb +34 -34
  14. data/spec/flipper/feature_spec.rb +167 -167
  15. data/spec/flipper/gate_spec.rb +5 -5
  16. data/spec/flipper/gate_values_spec.rb +17 -17
  17. data/spec/flipper/gates/actor_spec.rb +1 -1
  18. data/spec/flipper/gates/boolean_spec.rb +13 -13
  19. data/spec/flipper/gates/group_spec.rb +6 -6
  20. data/spec/flipper/gates/percentage_of_actors_spec.rb +3 -3
  21. data/spec/flipper/gates/percentage_of_time_spec.rb +1 -1
  22. data/spec/flipper/instrumentation/log_subscriber_spec.rb +10 -10
  23. data/spec/flipper/instrumentation/metriks_subscriber_spec.rb +14 -14
  24. data/spec/flipper/instrumentation/statsd_subscriber_spec.rb +5 -3
  25. data/spec/flipper/instrumenters/memory_spec.rb +4 -4
  26. data/spec/flipper/instrumenters/noop_spec.rb +3 -3
  27. data/spec/flipper/middleware/memoizer_spec.rb +8 -8
  28. data/spec/flipper/registry_spec.rb +17 -17
  29. data/spec/flipper/typecast_spec.rb +4 -4
  30. data/spec/flipper/types/actor_spec.rb +14 -14
  31. data/spec/flipper/types/boolean_spec.rb +5 -5
  32. data/spec/flipper/types/group_spec.rb +8 -8
  33. data/spec/flipper/types/percentage_of_actors_spec.rb +1 -1
  34. data/spec/flipper/types/percentage_of_time_spec.rb +1 -1
  35. data/spec/flipper/types/percentage_spec.rb +8 -8
  36. data/spec/flipper_spec.rb +19 -19
  37. data/spec/helper.rb +14 -14
  38. data/spec/integration_spec.rb +80 -80
  39. metadata +4 -3
@@ -3,7 +3,7 @@ require 'flipper/adapters/memoizable'
3
3
  require 'flipper/adapters/memory'
4
4
  require 'flipper/spec/shared_adapter_specs'
5
5
 
6
- describe Flipper::Adapters::Memoizable do
6
+ RSpec.describe Flipper::Adapters::Memoizable do
7
7
  let(:features_key) { described_class::FeaturesKey }
8
8
  let(:adapter) { Flipper::Adapters::Memory.new }
9
9
  let(:flipper) { Flipper.new(adapter) }
@@ -16,28 +16,28 @@ describe Flipper::Adapters::Memoizable do
16
16
  describe "#memoize=" do
17
17
  it "sets value" do
18
18
  subject.memoize = true
19
- subject.memoizing?.should eq(true)
19
+ expect(subject.memoizing?).to eq(true)
20
20
 
21
21
  subject.memoize = false
22
- subject.memoizing?.should eq(false)
22
+ expect(subject.memoizing?).to eq(false)
23
23
  end
24
24
 
25
25
  it "clears the local cache" do
26
26
  subject.cache['some'] = 'thing'
27
27
  subject.memoize = true
28
- subject.cache.should be_empty
28
+ expect(subject.cache).to be_empty
29
29
  end
30
30
  end
31
31
 
32
32
  describe "#memoizing?" do
33
33
  it "returns true if enabled" do
34
34
  subject.memoize = true
35
- subject.memoizing?.should eq(true)
35
+ expect(subject.memoizing?).to eq(true)
36
36
  end
37
37
 
38
38
  it "returns false if disabled" do
39
39
  subject.memoize = false
40
- subject.memoizing?.should eq(false)
40
+ expect(subject.memoizing?).to eq(false)
41
41
  end
42
42
  end
43
43
 
@@ -50,7 +50,7 @@ describe Flipper::Adapters::Memoizable do
50
50
  it "memoizes feature" do
51
51
  feature = flipper[:stats]
52
52
  result = subject.get(feature)
53
- cache[feature].should be(result)
53
+ expect(cache[feature]).to be(result)
54
54
  end
55
55
  end
56
56
 
@@ -63,7 +63,7 @@ describe Flipper::Adapters::Memoizable do
63
63
  feature = flipper[:stats]
64
64
  result = subject.get(feature)
65
65
  adapter_result = adapter.get(feature)
66
- result.should eq(adapter_result)
66
+ expect(result).to eq(adapter_result)
67
67
  end
68
68
  end
69
69
  end
@@ -79,7 +79,7 @@ describe Flipper::Adapters::Memoizable do
79
79
  gate = feature.gate(:boolean)
80
80
  cache[feature] = {:some => 'thing'}
81
81
  subject.enable(feature, gate, flipper.bool)
82
- cache[feature].should be_nil
82
+ expect(cache[feature]).to be_nil
83
83
  end
84
84
  end
85
85
 
@@ -93,7 +93,7 @@ describe Flipper::Adapters::Memoizable do
93
93
  gate = feature.gate(:boolean)
94
94
  result = subject.enable(feature, gate, flipper.bool)
95
95
  adapter_result = adapter.enable(feature, gate, flipper.bool)
96
- result.should eq(adapter_result)
96
+ expect(result).to eq(adapter_result)
97
97
  end
98
98
  end
99
99
  end
@@ -109,7 +109,7 @@ describe Flipper::Adapters::Memoizable do
109
109
  gate = feature.gate(:boolean)
110
110
  cache[feature] = {:some => 'thing'}
111
111
  subject.disable(feature, gate, flipper.bool)
112
- cache[feature].should be_nil
112
+ expect(cache[feature]).to be_nil
113
113
  end
114
114
  end
115
115
 
@@ -123,7 +123,7 @@ describe Flipper::Adapters::Memoizable do
123
123
  gate = feature.gate(:boolean)
124
124
  result = subject.disable(feature, gate, flipper.bool)
125
125
  adapter_result = adapter.disable(feature, gate, flipper.bool)
126
- result.should eq(adapter_result)
126
+ expect(result).to eq(adapter_result)
127
127
  end
128
128
  end
129
129
  end
@@ -138,7 +138,7 @@ describe Flipper::Adapters::Memoizable do
138
138
  flipper[:stats].enable
139
139
  flipper[:search].disable
140
140
  result = subject.features
141
- cache[:flipper_features].should be(result)
141
+ expect(cache[:flipper_features]).to be(result)
142
142
  end
143
143
  end
144
144
 
@@ -148,7 +148,7 @@ describe Flipper::Adapters::Memoizable do
148
148
  end
149
149
 
150
150
  it "returns result" do
151
- subject.features.should eq(adapter.features)
151
+ expect(subject.features).to eq(adapter.features)
152
152
  end
153
153
  end
154
154
  end
@@ -162,7 +162,7 @@ describe Flipper::Adapters::Memoizable do
162
162
  it "unmemoizes the known features" do
163
163
  cache[features_key] = {:some => 'thing'}
164
164
  subject.add(flipper[:stats])
165
- cache.should be_empty
165
+ expect(cache).to be_empty
166
166
  end
167
167
  end
168
168
 
@@ -172,7 +172,7 @@ describe Flipper::Adapters::Memoizable do
172
172
  end
173
173
 
174
174
  it "returns result" do
175
- subject.add(flipper[:stats]).should eq(adapter.add(flipper[:stats]))
175
+ expect(subject.add(flipper[:stats])).to eq(adapter.add(flipper[:stats]))
176
176
  end
177
177
  end
178
178
  end
@@ -186,14 +186,14 @@ describe Flipper::Adapters::Memoizable do
186
186
  it "unmemoizes the known features" do
187
187
  cache[features_key] = {:some => 'thing'}
188
188
  subject.remove(flipper[:stats])
189
- cache.should be_empty
189
+ expect(cache).to be_empty
190
190
  end
191
191
 
192
192
  it "unmemoizes the feature" do
193
193
  feature = flipper[:stats]
194
194
  cache[feature] = {:some => 'thing'}
195
195
  subject.remove(feature)
196
- cache[feature].should be_nil
196
+ expect(cache[feature]).to be_nil
197
197
  end
198
198
  end
199
199
 
@@ -203,7 +203,7 @@ describe Flipper::Adapters::Memoizable do
203
203
  end
204
204
 
205
205
  it "returns result" do
206
- subject.remove(flipper[:stats]).should eq(adapter.remove(flipper[:stats]))
206
+ expect(subject.remove(flipper[:stats])).to eq(adapter.remove(flipper[:stats]))
207
207
  end
208
208
  end
209
209
  end
@@ -218,7 +218,7 @@ describe Flipper::Adapters::Memoizable do
218
218
  feature = flipper[:stats]
219
219
  cache[feature] = {:some => 'thing'}
220
220
  subject.clear(feature)
221
- cache[feature].should be_nil
221
+ expect(cache[feature]).to be_nil
222
222
  end
223
223
  end
224
224
 
@@ -229,7 +229,7 @@ describe Flipper::Adapters::Memoizable do
229
229
 
230
230
  it "returns result" do
231
231
  feature = flipper[:stats]
232
- subject.clear(feature).should eq(adapter.clear(feature))
232
+ expect(subject.clear(feature)).to eq(adapter.clear(feature))
233
233
  end
234
234
  end
235
235
  end
@@ -2,7 +2,7 @@ require 'helper'
2
2
  require 'flipper/adapters/memory'
3
3
  require 'flipper/spec/shared_adapter_specs'
4
4
 
5
- describe Flipper::Adapters::Memory do
5
+ RSpec.describe Flipper::Adapters::Memory do
6
6
  subject { described_class.new }
7
7
 
8
8
  it_should_behave_like 'a flipper adapter'
@@ -3,7 +3,7 @@ require 'flipper/adapters/operation_logger'
3
3
  require 'flipper/adapters/memory'
4
4
  require 'flipper/spec/shared_adapter_specs'
5
5
 
6
- describe Flipper::Adapters::OperationLogger do
6
+ RSpec.describe Flipper::Adapters::OperationLogger do
7
7
  let(:operations) { [] }
8
8
  let(:adapter) { Flipper::Adapters::Memory.new }
9
9
  let(:flipper) { Flipper.new(adapter) }
@@ -19,11 +19,11 @@ describe Flipper::Adapters::OperationLogger do
19
19
  end
20
20
 
21
21
  it "logs operation" do
22
- subject.count(:get).should be(1)
22
+ expect(subject.count(:get)).to be(1)
23
23
  end
24
24
 
25
25
  it "returns result" do
26
- @result.should eq(adapter.get(@feature))
26
+ expect(@result).to eq(adapter.get(@feature))
27
27
  end
28
28
  end
29
29
 
@@ -36,11 +36,11 @@ describe Flipper::Adapters::OperationLogger do
36
36
  end
37
37
 
38
38
  it "logs operation" do
39
- subject.count(:enable).should be(1)
39
+ expect(subject.count(:enable)).to be(1)
40
40
  end
41
41
 
42
42
  it "returns result" do
43
- @result.should eq(adapter.enable(@feature, @gate, @thing))
43
+ expect(@result).to eq(adapter.enable(@feature, @gate, @thing))
44
44
  end
45
45
  end
46
46
 
@@ -53,11 +53,11 @@ describe Flipper::Adapters::OperationLogger do
53
53
  end
54
54
 
55
55
  it "logs operation" do
56
- subject.count(:disable).should be(1)
56
+ expect(subject.count(:disable)).to be(1)
57
57
  end
58
58
 
59
59
  it "returns result" do
60
- @result.should eq(adapter.disable(@feature, @gate, @thing))
60
+ expect(@result).to eq(adapter.disable(@feature, @gate, @thing))
61
61
  end
62
62
  end
63
63
 
@@ -68,11 +68,11 @@ describe Flipper::Adapters::OperationLogger do
68
68
  end
69
69
 
70
70
  it "logs operation" do
71
- subject.count(:features).should be(1)
71
+ expect(subject.count(:features)).to be(1)
72
72
  end
73
73
 
74
74
  it "returns result" do
75
- @result.should eq(adapter.features)
75
+ expect(@result).to eq(adapter.features)
76
76
  end
77
77
  end
78
78
 
@@ -83,11 +83,11 @@ describe Flipper::Adapters::OperationLogger do
83
83
  end
84
84
 
85
85
  it "logs operation" do
86
- subject.count(:add).should be(1)
86
+ expect(subject.count(:add)).to be(1)
87
87
  end
88
88
 
89
89
  it "returns result" do
90
- @result.should eq(adapter.add(@feature))
90
+ expect(@result).to eq(adapter.add(@feature))
91
91
  end
92
92
  end
93
93
  end
@@ -2,7 +2,7 @@ require 'helper'
2
2
  require 'flipper/adapters/pstore'
3
3
  require 'flipper/spec/shared_adapter_specs'
4
4
 
5
- describe Flipper::Adapters::PStore do
5
+ RSpec.describe Flipper::Adapters::PStore do
6
6
  subject {
7
7
  dir = FlipperRoot.join("tmp").tap { |d| d.mkpath }
8
8
  described_class.new(dir.join("flipper.pstore"))
@@ -11,6 +11,6 @@ describe Flipper::Adapters::PStore do
11
11
  it_should_behave_like 'a flipper adapter'
12
12
 
13
13
  it "defaults path to flipper.pstore" do
14
- described_class.new.path.should eq("flipper.pstore")
14
+ expect(described_class.new.path).to eq("flipper.pstore")
15
15
  end
16
16
  end
@@ -2,7 +2,7 @@ require 'helper'
2
2
  require 'flipper/dsl'
3
3
  require 'flipper/adapters/memory'
4
4
 
5
- describe Flipper::DSL do
5
+ RSpec.describe Flipper::DSL do
6
6
  subject { Flipper::DSL.new(adapter) }
7
7
 
8
8
  let(:adapter) { Flipper::Adapters::Memory.new }
@@ -10,12 +10,12 @@ describe Flipper::DSL do
10
10
  describe "#initialize" do
11
11
  it "sets adapter" do
12
12
  dsl = described_class.new(adapter)
13
- dsl.adapter.should_not be_nil
13
+ expect(dsl.adapter).not_to be_nil
14
14
  end
15
15
 
16
16
  it "defaults instrumenter to noop" do
17
17
  dsl = described_class.new(adapter)
18
- dsl.instrumenter.should be(Flipper::Instrumenters::Noop)
18
+ expect(dsl.instrumenter).to be(Flipper::Instrumenters::Noop)
19
19
  end
20
20
 
21
21
  context "with overriden instrumenter" do
@@ -23,12 +23,12 @@ describe Flipper::DSL do
23
23
 
24
24
  it "overrides default instrumenter" do
25
25
  dsl = described_class.new(adapter, :instrumenter => instrumenter)
26
- dsl.instrumenter.should be(instrumenter)
26
+ expect(dsl.instrumenter).to be(instrumenter)
27
27
  end
28
28
 
29
29
  it "passes overridden instrumenter to adapter wrapping" do
30
30
  dsl = described_class.new(adapter, :instrumenter => instrumenter)
31
- dsl.adapter.instrumenter.should be(instrumenter)
31
+ expect(dsl.adapter.instrumenter).to be(instrumenter)
32
32
  end
33
33
  end
34
34
  end
@@ -70,11 +70,11 @@ describe Flipper::DSL do
70
70
  end
71
71
 
72
72
  it "returns group" do
73
- subject.group(:admins).should eq(@group)
73
+ expect(subject.group(:admins)).to eq(@group)
74
74
  end
75
75
 
76
76
  it "always returns same instance for same name" do
77
- subject.group(:admins).should equal(subject.group(:admins))
77
+ expect(subject.group(:admins)).to equal(subject.group(:admins))
78
78
  end
79
79
  end
80
80
 
@@ -92,8 +92,8 @@ describe Flipper::DSL do
92
92
  it "returns actor instance" do
93
93
  thing = Struct.new(:flipper_id).new(33)
94
94
  actor = subject.actor(thing)
95
- actor.should be_instance_of(Flipper::Types::Actor)
96
- actor.value.should eq('33')
95
+ expect(actor).to be_instance_of(Flipper::Types::Actor)
96
+ expect(actor.value).to eq('33')
97
97
  end
98
98
  end
99
99
 
@@ -120,15 +120,15 @@ describe Flipper::DSL do
120
120
  end
121
121
 
122
122
  it "returns percentage of time" do
123
- @result.should be_instance_of(Flipper::Types::PercentageOfTime)
123
+ expect(@result).to be_instance_of(Flipper::Types::PercentageOfTime)
124
124
  end
125
125
 
126
126
  it "sets value" do
127
- @result.value.should eq(5)
127
+ expect(@result.value).to eq(5)
128
128
  end
129
129
 
130
130
  it "is aliased to percentage_of_time" do
131
- @result.should eq(subject.percentage_of_time(@result.value))
131
+ expect(@result).to eq(subject.percentage_of_time(@result.value))
132
132
  end
133
133
  end
134
134
 
@@ -138,22 +138,22 @@ describe Flipper::DSL do
138
138
  end
139
139
 
140
140
  it "returns percentage of actors" do
141
- @result.should be_instance_of(Flipper::Types::PercentageOfActors)
141
+ expect(@result).to be_instance_of(Flipper::Types::PercentageOfActors)
142
142
  end
143
143
 
144
144
  it "sets value" do
145
- @result.value.should eq(17)
145
+ expect(@result.value).to eq(17)
146
146
  end
147
147
 
148
148
  it "is aliased to percentage_of_actors" do
149
- @result.should eq(subject.percentage_of_actors(@result.value))
149
+ expect(@result).to eq(subject.percentage_of_actors(@result.value))
150
150
  end
151
151
  end
152
152
 
153
153
  describe "#features" do
154
154
  context "with no features enabled/disabled" do
155
155
  it "defaults to empty set" do
156
- subject.features.should eq(Set.new)
156
+ expect(subject.features).to eq(Set.new)
157
157
  end
158
158
  end
159
159
 
@@ -165,23 +165,23 @@ describe Flipper::DSL do
165
165
  end
166
166
 
167
167
  it "returns set of feature instances" do
168
- subject.features.should be_instance_of(Set)
168
+ expect(subject.features).to be_instance_of(Set)
169
169
  subject.features.each do |feature|
170
- feature.should be_instance_of(Flipper::Feature)
170
+ expect(feature).to be_instance_of(Flipper::Feature)
171
171
  end
172
- subject.features.map(&:name).map(&:to_s).sort.should eq(['cache', 'search', 'stats'])
172
+ expect(subject.features.map(&:name).map(&:to_s).sort).to eq(['cache', 'search', 'stats'])
173
173
  end
174
174
  end
175
175
  end
176
176
 
177
177
  describe "#enable/disable" do
178
178
  it "enables and disables the feature" do
179
- subject[:stats].boolean_value.should eq(false)
179
+ expect(subject[:stats].boolean_value).to eq(false)
180
180
  subject.enable(:stats)
181
- subject[:stats].boolean_value.should eq(true)
181
+ expect(subject[:stats].boolean_value).to eq(true)
182
182
 
183
183
  subject.disable(:stats)
184
- subject[:stats].boolean_value.should eq(false)
184
+ expect(subject[:stats].boolean_value).to eq(false)
185
185
  end
186
186
  end
187
187
 
@@ -189,12 +189,12 @@ describe Flipper::DSL do
189
189
  it "enables and disables the feature for actor" do
190
190
  actor = Struct.new(:flipper_id).new(5)
191
191
 
192
- subject[:stats].actors_value.should be_empty
192
+ expect(subject[:stats].actors_value).to be_empty
193
193
  subject.enable_actor(:stats, actor)
194
- subject[:stats].actors_value.should eq(Set["5"])
194
+ expect(subject[:stats].actors_value).to eq(Set["5"])
195
195
 
196
196
  subject.disable_actor(:stats, actor)
197
- subject[:stats].actors_value.should be_empty
197
+ expect(subject[:stats].actors_value).to be_empty
198
198
  end
199
199
  end
200
200
 
@@ -203,34 +203,34 @@ describe Flipper::DSL do
203
203
  actor = Struct.new(:flipper_id).new(5)
204
204
  group = Flipper.register(:fives) { |actor| actor.flipper_id == 5 }
205
205
 
206
- subject[:stats].groups_value.should be_empty
206
+ expect(subject[:stats].groups_value).to be_empty
207
207
  subject.enable_group(:stats, :fives)
208
- subject[:stats].groups_value.should eq(Set["fives"])
208
+ expect(subject[:stats].groups_value).to eq(Set["fives"])
209
209
 
210
210
  subject.disable_group(:stats, :fives)
211
- subject[:stats].groups_value.should be_empty
211
+ expect(subject[:stats].groups_value).to be_empty
212
212
  end
213
213
  end
214
214
 
215
215
  describe "#enable_percentage_of_time/disable_percentage_of_time" do
216
216
  it "enables and disables the feature for percentage of time" do
217
- subject[:stats].percentage_of_time_value.should be(0)
217
+ expect(subject[:stats].percentage_of_time_value).to be(0)
218
218
  subject.enable_percentage_of_time(:stats, 6)
219
- subject[:stats].percentage_of_time_value.should be(6)
219
+ expect(subject[:stats].percentage_of_time_value).to be(6)
220
220
 
221
221
  subject.disable_percentage_of_time(:stats)
222
- subject[:stats].percentage_of_time_value.should be(0)
222
+ expect(subject[:stats].percentage_of_time_value).to be(0)
223
223
  end
224
224
  end
225
225
 
226
226
  describe "#enable_percentage_of_actors/disable_percentage_of_actors" do
227
227
  it "enables and disables the feature for percentage of time" do
228
- subject[:stats].percentage_of_actors_value.should be(0)
228
+ expect(subject[:stats].percentage_of_actors_value).to be(0)
229
229
  subject.enable_percentage_of_actors(:stats, 6)
230
- subject[:stats].percentage_of_actors_value.should be(6)
230
+ expect(subject[:stats].percentage_of_actors_value).to be(6)
231
231
 
232
232
  subject.disable_percentage_of_actors(:stats)
233
- subject[:stats].percentage_of_actors_value.should be(0)
233
+ expect(subject[:stats].percentage_of_actors_value).to be(0)
234
234
  end
235
235
  end
236
236
  end