flipper 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,7 @@ RSpec.describe Flipper::Middleware::Memoizer do
17
17
  flipper.adapter.memoize = nil
18
18
  end
19
19
 
20
- shared_examples_for "flipper middleware" do
20
+ RSpec.shared_examples_for "flipper middleware" do
21
21
  it "delegates" do
22
22
  called = false
23
23
  app = lambda { |env|
@@ -2,6 +2,8 @@ require 'helper'
2
2
  require 'flipper/types/group'
3
3
 
4
4
  RSpec.describe Flipper::Types::Group do
5
+ let(:fake_context) { double("FeatureCheckContext") }
6
+
5
7
  subject do
6
8
  Flipper.register(:admins) { |actor| actor.admin? }
7
9
  end
@@ -42,25 +44,48 @@ RSpec.describe Flipper::Types::Group do
42
44
  let(:non_admin_actor) { double('Actor', :admin? => false) }
43
45
 
44
46
  it "returns true if block matches" do
45
- expect(subject.match?(admin_actor)).to eq(true)
47
+ expect(subject.match?(admin_actor, fake_context)).to eq(true)
46
48
  end
47
49
 
48
50
  it "returns false if block does not match" do
49
- expect(subject.match?(non_admin_actor)).to eq(false)
51
+ expect(subject.match?(non_admin_actor, fake_context)).to eq(false)
50
52
  end
51
53
 
52
54
  it "returns true for truthy block results" do
53
55
  group = Flipper::Types::Group.new(:examples) do |actor|
54
56
  actor.email =~ /@example\.com/
55
57
  end
56
- expect(group.match?(double('Actor', :email => "foo@example.com"))).to be_truthy
58
+ expect(group.match?(double('Actor', :email => "foo@example.com"), fake_context)).to be_truthy
57
59
  end
58
60
 
59
61
  it "returns false for falsey block results" do
60
62
  group = Flipper::Types::Group.new(:examples) do |actor|
61
63
  nil
62
64
  end
63
- expect(group.match?(double('Actor'))).to be_falsey
65
+ expect(group.match?(double('Actor'), fake_context)).to be_falsey
66
+ end
67
+
68
+ it "can yield without context as block argument" do
69
+ context = Flipper::FeatureCheckContext.new(
70
+ feature_name: :my_feature,
71
+ values: Flipper::GateValues.new({}),
72
+ thing: Flipper::Types::Actor.new(Struct.new(:flipper_id).new(1)),
73
+ )
74
+ group = Flipper.register(:group_with_context) { |actor| actor }
75
+ yielded_actor = group.match?(admin_actor, context)
76
+ expect(yielded_actor).to be(admin_actor)
77
+ end
78
+
79
+ it "can yield with context as block argument" do
80
+ context = Flipper::FeatureCheckContext.new(
81
+ feature_name: :my_feature,
82
+ values: Flipper::GateValues.new({}),
83
+ thing: Flipper::Types::Actor.new(Struct.new(:flipper_id).new(1)),
84
+ )
85
+ group = Flipper.register(:group_with_context) { |actor, context| [actor, context] }
86
+ yielded_actor, yielded_context = group.match?(admin_actor, context)
87
+ expect(yielded_actor).to be(admin_actor)
88
+ expect(yielded_context).to be(context)
64
89
  end
65
90
  end
66
91
  end
data/spec/helper.rb CHANGED
@@ -19,6 +19,8 @@ RSpec.configure do |config|
19
19
  Flipper.unregister_groups
20
20
  end
21
21
 
22
+ config.disable_monkey_patching!
23
+
22
24
  config.filter_run focus: true
23
25
  config.run_all_when_everything_filtered = true
24
26
  end
@@ -52,7 +54,7 @@ RSpec.shared_examples_for 'a percentage' do
52
54
  end
53
55
  end
54
56
 
55
- shared_examples_for 'a DSL feature' do
57
+ RSpec.shared_examples_for 'a DSL feature' do
56
58
  it "returns instance of feature" do
57
59
  expect(feature).to be_instance_of(Flipper::Feature)
58
60
  end
@@ -80,7 +82,7 @@ shared_examples_for 'a DSL feature' do
80
82
  end
81
83
  end
82
84
 
83
- shared_examples_for "a DSL boolean method" do
85
+ RSpec.shared_examples_for "a DSL boolean method" do
84
86
  it "returns boolean with value set" do
85
87
  result = subject.send(method_name, true)
86
88
  expect(result).to be_instance_of(Flipper::Types::Boolean)
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.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-22 00:00:00.000000000 Z
11
+ date: 2016-11-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Feature flipper is the act of enabling/disabling features in your application,
14
14
  ideally without re-deploying or changing anything in your code base. Flipper makes
@@ -29,11 +29,13 @@ files:
29
29
  - docs/Gates.md
30
30
  - docs/Instrumentation.md
31
31
  - docs/Optimization.md
32
+ - docs/api/README.md
32
33
  - examples/basic.rb
33
34
  - examples/dsl.rb
34
35
  - examples/enabled_for_actor.rb
35
36
  - examples/example_setup.rb
36
37
  - examples/group.rb
38
+ - examples/group_dynamic_lookup.rb
37
39
  - examples/group_with_members.rb
38
40
  - examples/individual_actor.rb
39
41
  - examples/instrumentation.rb
@@ -52,6 +54,7 @@ files:
52
54
  - lib/flipper/dsl.rb
53
55
  - lib/flipper/errors.rb
54
56
  - lib/flipper/feature.rb
57
+ - lib/flipper/feature_check_context.rb
55
58
  - lib/flipper/gate.rb
56
59
  - lib/flipper/gate_values.rb
57
60
  - lib/flipper/gates/actor.rb
@@ -87,6 +90,7 @@ files:
87
90
  - spec/flipper/adapters/pstore_spec.rb
88
91
  - spec/flipper/adapters/read_only_spec.rb
89
92
  - spec/flipper/dsl_spec.rb
93
+ - spec/flipper/feature_check_context_spec.rb
90
94
  - spec/flipper/feature_spec.rb
91
95
  - spec/flipper/gate_spec.rb
92
96
  - spec/flipper/gate_values_spec.rb
@@ -150,6 +154,7 @@ test_files:
150
154
  - spec/flipper/adapters/pstore_spec.rb
151
155
  - spec/flipper/adapters/read_only_spec.rb
152
156
  - spec/flipper/dsl_spec.rb
157
+ - spec/flipper/feature_check_context_spec.rb
153
158
  - spec/flipper/feature_spec.rb
154
159
  - spec/flipper/gate_spec.rb
155
160
  - spec/flipper/gate_values_spec.rb