feature 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +6 -4
- data/Rakefile +1 -1
- data/lib/feature/repository/yaml_repository.rb +13 -4
- data/lib/feature/testing.rb +28 -12
- data/spec/feature/feature_spec.rb +2 -4
- data/spec/feature/redis_repository_spec.rb +0 -1
- data/spec/feature/testing_spec.rb +91 -14
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19c7e68f322b7bd8ecc077e38301ca81f0101b98
|
4
|
+
data.tar.gz: 6494be8fbf82513c8bc3584f5b79ee64db13dce8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2552d77a0338981f11f30520712345a6f0e1b45f827748004fcf1fe373e6f0304826fd433bdadf2e572812705d96c7b5bf9d4e9f254d57803016c182b5414dc
|
7
|
+
data.tar.gz: 0b0208a6710fd63b2fdecc397a16895ad52cfc814465bc42ef2d49292e7bd242035794c652f803b13914fd0ef1d72b31f57980b61facaad31154b4f03bc06b97
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 1.3.0 (2015-06-12)
|
2
|
+
|
3
|
+
* Support testing with multiple features (stevenwilkin)
|
4
|
+
* Bugfix when using auto_refresh and testing support (javidjamae)
|
5
|
+
* Fixing an issue with Feature.run_with_activated if @active_features is nil (tommyh)
|
6
|
+
|
1
7
|
## 1.2.0 (2014-10-28)
|
2
8
|
|
3
9
|
* add Support for auto-refresh of feature data (javidjamae)
|
data/README.md
CHANGED
@@ -13,9 +13,11 @@ The feature toggle functionality has to be configured by feature repositories. A
|
|
13
13
|
|
14
14
|
With this approach Feature is higly configurable and not bound to a specific kind of configuration.
|
15
15
|
|
16
|
-
**NOTE:** Ruby 1.
|
16
|
+
**NOTE:** Ruby 1.9 is supported explicitly only until version 1.2.0. Later version may require 2+.
|
17
17
|
|
18
|
-
**NOTE:**
|
18
|
+
**NOTE:** Ruby 1.8 is only supported until version 0.7.0. Later Versions require Ruby 1.9+.
|
19
|
+
|
20
|
+
**NOTE:** Using feature with ActiveRecord and Rails 3 MAY work. Version 1.1.0 supports Rails 3.
|
19
21
|
|
20
22
|
## Installation
|
21
23
|
|
@@ -52,11 +54,11 @@ With this approach Feature is higly configurable and not bound to a specific kin
|
|
52
54
|
|
53
55
|
require 'feature/testing'
|
54
56
|
|
55
|
-
Feature.run_with_activated(:
|
57
|
+
Feature.run_with_activated(:feature) do
|
56
58
|
# your test code
|
57
59
|
end
|
58
60
|
|
59
|
-
Feature.run_with_deactivated(:
|
61
|
+
Feature.run_with_deactivated(:feature, :another_feature) do
|
60
62
|
# your test code
|
61
63
|
end
|
62
64
|
|
data/Rakefile
CHANGED
@@ -71,14 +71,23 @@ module Feature
|
|
71
71
|
|
72
72
|
return [] unless data['features']
|
73
73
|
|
74
|
-
|
75
|
-
unless invalid_value.empty?
|
76
|
-
fail ArgumentError, "#{invalid_value.first} is not allowed value in config, use true/false"
|
77
|
-
end
|
74
|
+
check_valid_feature_data(data['features'])
|
78
75
|
|
79
76
|
data['features'].keys.select { |key| data['features'][key] }.map(&:to_sym)
|
80
77
|
end
|
81
78
|
private :get_active_features
|
79
|
+
|
80
|
+
# Checks for valid values in given feature hash
|
81
|
+
#
|
82
|
+
# @param features [Hash] feature hash
|
83
|
+
#
|
84
|
+
def check_valid_feature_data(features)
|
85
|
+
features.values.each do |value|
|
86
|
+
unless [true, false].include?(value)
|
87
|
+
fail ArgumentError, "#{value} is not allowed value in config, use true/false"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
82
91
|
end
|
83
92
|
end
|
84
93
|
end
|
data/lib/feature/testing.rb
CHANGED
@@ -7,31 +7,47 @@ require 'feature'
|
|
7
7
|
# To enable Feature testing capabilities do:
|
8
8
|
# require 'feature/testing'
|
9
9
|
module Feature
|
10
|
-
# Execute the code block with the given
|
10
|
+
# Execute the code block with the given features active
|
11
11
|
#
|
12
12
|
# Example usage:
|
13
|
-
# Feature.run_with_activated(:feature) do
|
13
|
+
# Feature.run_with_activated(:feature, :another_feature) do
|
14
14
|
# # your test code here
|
15
15
|
# end
|
16
|
-
def self.run_with_activated(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
def self.run_with_activated(*features, &blk)
|
17
|
+
with_stashed_config do
|
18
|
+
@active_features.concat(features).uniq!
|
19
|
+
@auto_refresh = false
|
20
|
+
@perform_initial_refresh = false
|
21
|
+
blk.call
|
22
|
+
end
|
22
23
|
end
|
23
24
|
|
24
|
-
# Execute the code block with the given
|
25
|
+
# Execute the code block with the given features deactive
|
25
26
|
#
|
26
27
|
# Example usage:
|
27
|
-
# Feature.run_with_deactivated(:feature) do
|
28
|
+
# Feature.run_with_deactivated(:feature, :another_feature) do
|
28
29
|
# # your test code here
|
29
30
|
# end
|
30
|
-
def self.run_with_deactivated(
|
31
|
+
def self.run_with_deactivated(*features, &blk)
|
32
|
+
with_stashed_config do
|
33
|
+
@active_features -= features
|
34
|
+
@auto_refresh = false
|
35
|
+
@perform_initial_refresh = false
|
36
|
+
blk.call
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Execute the given code block and store + restore the feature
|
41
|
+
# configuration before/after the execution
|
42
|
+
def self.with_stashed_config
|
43
|
+
@active_features = [] if @active_features.nil?
|
31
44
|
old_features = @active_features.dup
|
32
|
-
@
|
45
|
+
old_auto_refresh = @auto_refresh
|
46
|
+
old_perform_initial_refresh = @perform_initial_refresh
|
33
47
|
yield
|
34
48
|
ensure
|
35
49
|
@active_features = old_features
|
50
|
+
@auto_refresh = old_auto_refresh
|
51
|
+
@perform_initial_refresh = old_perform_initial_refresh
|
36
52
|
end
|
37
53
|
end
|
@@ -58,8 +58,7 @@ describe Feature do
|
|
58
58
|
|
59
59
|
it 'should reload active features on first call only' do
|
60
60
|
@repository.add_active_feature(:feature_a)
|
61
|
-
expect(@repository).to receive(:active_features).
|
62
|
-
.and_return(@repository.active_features)
|
61
|
+
expect(@repository).to receive(:active_features).once.and_return(@repository.active_features)
|
63
62
|
Feature.active?(:feature_a)
|
64
63
|
Feature.active?(:feature_a)
|
65
64
|
end
|
@@ -71,8 +70,7 @@ describe Feature do
|
|
71
70
|
end
|
72
71
|
it 'should reload active features on every call' do
|
73
72
|
@repository.add_active_feature(:feature_a)
|
74
|
-
expect(@repository).to receive(:active_features).
|
75
|
-
.and_return(@repository.active_features)
|
73
|
+
expect(@repository).to receive(:active_features).twice.and_return(@repository.active_features)
|
76
74
|
Feature.active?(:feature_a)
|
77
75
|
Feature.active?(:feature_a)
|
78
76
|
end
|
@@ -1,30 +1,107 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'feature/testing'
|
3
3
|
|
4
|
+
shared_examples 'a testable repository' do
|
5
|
+
before do
|
6
|
+
expect(Feature.active?(:active_feature)).to be_truthy
|
7
|
+
expect(Feature.active?(:another_active_feature)).to be_truthy
|
8
|
+
expect(Feature.active?(:deactive_feature)).to be_falsey
|
9
|
+
expect(Feature.active?(:another_deactive_feature)).to be_falsey
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
expect(Feature.active?(:active_feature)).to be_truthy
|
14
|
+
expect(Feature.active?(:another_active_feature)).to be_truthy
|
15
|
+
expect(Feature.active?(:deactive_feature)).to be_falsey
|
16
|
+
expect(Feature.active?(:another_deactive_feature)).to be_falsey
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.run_with_activated' do
|
20
|
+
it 'activates a deactivated feature' do
|
21
|
+
Feature.run_with_activated(:deactive_feature) do
|
22
|
+
expect(Feature.active?(:deactive_feature)).to be_truthy
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'activates multiple deactivated features' do
|
27
|
+
Feature.run_with_activated(:deactive_feature, :another_deactive_feature) do
|
28
|
+
expect(Feature.active?(:deactive_feature)).to be_truthy
|
29
|
+
expect(Feature.active?(:another_deactive_feature)).to be_truthy
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.run_with_deactivated' do
|
35
|
+
it 'deactivates an activated feature' do
|
36
|
+
Feature.run_with_deactivated(:active_feature) do
|
37
|
+
expect(Feature.active?(:active_feature)).to be_falsey
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'deactivates multiple activated features' do
|
42
|
+
Feature.run_with_deactivated(:active_feature, :another_active_feature) do
|
43
|
+
expect(Feature.active?(:active_feature)).to be_falsey
|
44
|
+
expect(Feature.active?(:another_active_feature)).to be_falsey
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
4
50
|
describe 'Feature testing support' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
51
|
+
context 'without auto_refresh' do
|
52
|
+
before(:all) do
|
53
|
+
repository = Feature::Repository::SimpleRepository.new
|
54
|
+
repository.add_active_feature(:active_feature)
|
55
|
+
repository.add_active_feature(:another_active_feature)
|
56
|
+
Feature.set_repository(repository)
|
57
|
+
end
|
58
|
+
|
59
|
+
it_behaves_like 'a testable repository'
|
9
60
|
end
|
10
61
|
|
11
|
-
|
12
|
-
|
62
|
+
context 'with auto_refresh' do
|
63
|
+
before(:all) do
|
64
|
+
repository = Feature::Repository::SimpleRepository.new
|
65
|
+
repository.add_active_feature(:active_feature)
|
66
|
+
repository.add_active_feature(:another_active_feature)
|
67
|
+
Feature.set_repository(repository, true)
|
68
|
+
end
|
13
69
|
|
14
|
-
|
15
|
-
|
70
|
+
it_behaves_like 'a testable repository'
|
71
|
+
|
72
|
+
describe '.run_with_deactivated' do
|
73
|
+
it 'should disable perform_initial_refresh for the first call to Feature.active?' do
|
74
|
+
Feature.run_with_activated(:deactive_feature) do
|
75
|
+
expect(Feature.active?(:deactive_feature)).to be_truthy
|
76
|
+
end
|
77
|
+
end
|
16
78
|
end
|
17
79
|
|
18
|
-
|
80
|
+
describe '.run_with_deactivated' do
|
81
|
+
it 'should disable perform_initial_refresh for the first call to Feature.active?' do
|
82
|
+
Feature.run_with_deactivated(:active_feature) do
|
83
|
+
expect(Feature.active?(:active_feature)).to be_falsey
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
19
87
|
end
|
20
88
|
|
21
|
-
|
22
|
-
|
89
|
+
context 'with no features activated' do
|
90
|
+
before(:all) do
|
91
|
+
repository = Feature::Repository::SimpleRepository.new
|
92
|
+
Feature.set_repository(repository)
|
93
|
+
end
|
23
94
|
|
24
|
-
|
25
|
-
|
95
|
+
describe '.run_with_activated' do
|
96
|
+
it 'should not raise an error' do
|
97
|
+
expect { Feature.run_with_activated(:foo) {} }.to_not raise_error
|
98
|
+
end
|
26
99
|
end
|
27
100
|
|
28
|
-
|
101
|
+
describe '.run_with_deactivated' do
|
102
|
+
it 'should not raise an error' do
|
103
|
+
expect { Feature.run_with_deactivated(:foo) {} }.to_not raise_error
|
104
|
+
end
|
105
|
+
end
|
29
106
|
end
|
30
107
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feature
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Gerdes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: github@mgsnova.de
|
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
version: '0'
|
61
61
|
requirements: []
|
62
62
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.4.8
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: Feature Toggle library for ruby
|