This repository has been archived by the owner on Jul 22, 2023. It is now read-only.
forked from freddi-kit/fastlane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature_spec.rb
139 lines (116 loc) · 5.58 KB
/
feature_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
class FeatureHelper
def self.disabled_class_method
end
def self.enabled_class_method
end
def disabled_instance_method; end
def enabled_instance_method; end
def self.reset_test_method
FeatureHelper.instance_eval { undef test_method }
end
def reset_test_method
undef test_method
end
end
describe FastlaneCore do
describe FastlaneCore::Feature do
describe "Register a Feature" do
it "registers a feature successfully with environment variable and description" do
expect do
FastlaneCore::Feature.register(env_var: "TEST_ENV_VAR_VALID", description: "A valid test feature")
end.not_to(raise_error)
end
it "raises an error if no environment variable specified" do
expect do
FastlaneCore::Feature.register(description: "An invalid test feature")
end.to raise_error("Invalid Feature")
end
it "raises an error if no description specified" do
expect do
FastlaneCore::Feature.register(env_var: "TEST_ENV_VAR_INVALID_NO_DESCRIPTION")
end.to raise_error("Invalid Feature")
end
end
describe '#enabled?' do
before(:all) do
FastlaneCore::Feature.register(env_var: 'TEST_ENV_VAR_FOR_ENABLED_TESTS', description: 'Test feature for enabled? tests')
end
it "reports unregistered features as not enabled" do
expect(FastlaneCore::Feature.enabled?('TEST_ENV_VAR_NOT_REGISTERED')).to be_falsey
end
it "reports undefined features as not enabled, even if the environment variable is set" do
with_env_values('TEST_ENV_VAR_NOT_REGISTERED' => '1') do
expect(FastlaneCore::Feature.enabled?('TEST_ENV_VAR_NOT_REGISTERED')).to be_falsey
end
end
it "reports features for missing environment variables as disabled" do
expect(FastlaneCore::Feature.enabled?('TEST_ENV_VAR_FOR_ENABLED_TESTS')).to be_falsey
end
it "reports features for disabled environment variables as disabled" do
with_env_values('TEST_ENV_VAR_FOR_ENABLED_TESTS' => '0') do
expect(FastlaneCore::Feature.enabled?('TEST_ENV_VAR_FOR_ENABLED_TESTS')).to be_falsey
end
end
it "reports features for environment variables as enabled" do
with_env_values('TEST_ENV_VAR_FOR_ENABLED_TESTS' => '1') do
expect(FastlaneCore::Feature.enabled?('TEST_ENV_VAR_FOR_ENABLED_TESTS')).to be_truthy
end
end
end
describe "Register feature methods" do
before(:all) do
FastlaneCore::Feature.register(env_var: 'TEST_ENV_VAR_FOR_METHOD_TESTS', description: 'Test feature for feature method registration tests')
end
it "Calls disabled class method with disabled environment variable" do
with_env_values('TEST_ENV_VAR_FOR_METHOD_TESTS' => '0') do
FastlaneCore::Feature.register_class_method(klass: FeatureHelper,
symbol: :test_method,
disabled_symbol: :disabled_class_method,
enabled_symbol: :enabled_class_method,
env_var: 'TEST_ENV_VAR_FOR_METHOD_TESTS')
expect(FeatureHelper).to receive(:disabled_class_method)
FeatureHelper.test_method
FeatureHelper.reset_test_method
end
end
it "Calls enabled class method with enabled environment variable" do
with_env_values('TEST_ENV_VAR_FOR_METHOD_TESTS' => '1') do
FastlaneCore::Feature.register_class_method(klass: FeatureHelper,
symbol: :test_method,
disabled_symbol: :disabled_class_method,
enabled_symbol: :enabled_class_method,
env_var: 'TEST_ENV_VAR_FOR_METHOD_TESTS')
expect(FeatureHelper).to receive(:enabled_class_method)
FeatureHelper.test_method
FeatureHelper.reset_test_method
end
end
it "Calls disabled instance method with disabled environment variable" do
with_env_values('TEST_ENV_VAR_FOR_METHOD_TESTS' => '0') do
instance = FeatureHelper.new
FastlaneCore::Feature.register_instance_method(klass: FeatureHelper,
symbol: :test_method,
disabled_symbol: :disabled_instance_method,
enabled_symbol: :enabled_instance_method,
env_var: 'TEST_ENV_VAR_FOR_METHOD_TESTS')
expect(instance).to receive(:disabled_instance_method)
instance.test_method
instance.reset_test_method
end
end
it "Calls enabled instance method with enabled environment variable" do
with_env_values('TEST_ENV_VAR_FOR_METHOD_TESTS' => '1') do
instance = FeatureHelper.new
FastlaneCore::Feature.register_instance_method(klass: FeatureHelper,
symbol: :test_method,
disabled_symbol: :disabled_instance_method,
enabled_symbol: :enabled_instance_method,
env_var: 'TEST_ENV_VAR_FOR_METHOD_TESTS')
expect(instance).to receive(:enabled_instance_method)
instance.test_method
instance.reset_test_method
end
end
end
end
end