|
28 | 28 | context 'with invalid UFC JSON' do |
29 | 29 | it 'stores parse error for malformed JSON' do |
30 | 30 | evaluator = described_class.new('invalid json') |
31 | | - result = evaluator.get_assignment('any_flag', {}, 'string', 'test_default') |
| 31 | + result = evaluator.get_assignment('any_flag', 'test_default', {}, 'string') |
32 | 32 |
|
33 | 33 | expect(result.error_code).to eq('CONFIGURATION_PARSE_ERROR') |
34 | 34 | expect(result.error_message).to eq('failed to parse configuration') |
|
38 | 38 |
|
39 | 39 | it 'stores configuration missing error for empty JSON' do |
40 | 40 | evaluator = described_class.new('') |
41 | | - result = evaluator.get_assignment('any_flag', {}, 'string', 'test_default') |
| 41 | + result = evaluator.get_assignment('any_flag', 'test_default', {}, 'string') |
42 | 42 |
|
43 | 43 | expect(result.error_code).to eq('CONFIGURATION_MISSING') |
44 | 44 | expect(result.error_message).to eq('flags configuration is missing') |
|
55 | 55 | let(:bad_evaluator) { described_class.new('invalid json') } |
56 | 56 |
|
57 | 57 | it 'returns the initialization error' do |
58 | | - result = bad_evaluator.get_assignment('any_flag', {}, 'string', 'test_default') |
| 58 | + result = bad_evaluator.get_assignment('any_flag', 'test_default', {}, 'string') |
59 | 59 |
|
60 | 60 | expect(result.error_code).to eq('CONFIGURATION_PARSE_ERROR') |
61 | 61 | expect(result.error_message).to eq('failed to parse configuration') |
|
67 | 67 |
|
68 | 68 | context 'with type validation' do |
69 | 69 | it 'returns TYPE_MISMATCH when types do not match' do |
70 | | - result = evaluator.get_assignment('numeric_flag', {}, 'boolean', 'test_default') |
| 70 | + result = evaluator.get_assignment('numeric_flag', 'test_default', {}, 'boolean') |
71 | 71 |
|
72 | 72 | expect(result.error_code).to eq('TYPE_MISMATCH') |
73 | 73 | expect(result.error_message).to eq('invalid flag type (expected: boolean, found: NUMERIC)') |
|
77 | 77 | end |
78 | 78 |
|
79 | 79 | it 'succeeds when types match' do |
80 | | - result = evaluator.get_assignment('numeric_flag', {}, 'float', 'test_default') |
| 80 | + result = evaluator.get_assignment('numeric_flag', 'test_default', {}, 'float') |
81 | 81 |
|
82 | 82 | expect(result.error_code).to be_nil # nil for successful allocation match |
83 | 83 | expect(result.error_message).to be_nil # nil for successful cases |
|
89 | 89 | end |
90 | 90 |
|
91 | 91 | it 'succeeds when expected_type is nil (no validation)' do |
92 | | - result = evaluator.get_assignment('numeric_flag', {}, nil, 'test_default') |
| 92 | + result = evaluator.get_assignment('numeric_flag', 'test_default', {}, nil) |
93 | 93 |
|
94 | 94 | expect(result.error_code).to be_nil # nil for successful allocation match |
95 | 95 | expect(result.error_message).to be_nil # nil for successful cases |
|
123 | 123 | it 'accepts hash evaluation contexts including from OpenFeature SDK fields' do |
124 | 124 | # Test with hash-based evaluation context |
125 | 125 | hash_context = {'targeting_key' => 'user123', 'attr1' => 'value1'} |
126 | | - hash_result = evaluator.get_assignment('numeric_flag', hash_context, 'float', 'test_default') |
| 126 | + hash_result = evaluator.get_assignment('numeric_flag', 'test_default', hash_context, 'float') |
127 | 127 |
|
128 | 128 | expect(hash_result.error_code).to be_nil |
129 | 129 | expect(hash_result.value).not_to be_nil |
|
135 | 135 | fields: {'attr1' => 'value1'} |
136 | 136 | ) |
137 | 137 |
|
138 | | - sdk_result = evaluator.get_assignment('numeric_flag', sdk_context.fields, 'float', 'test_default') |
| 138 | + sdk_result = evaluator.get_assignment('numeric_flag', 'test_default', sdk_context.fields, 'float') |
139 | 139 |
|
140 | 140 | expect(sdk_result.error_code).to be_nil |
141 | 141 | expect(sdk_result.value).not_to be_nil |
|
174 | 174 |
|
175 | 175 | it 'uses consistent error codes matching Rust implementation' do |
176 | 176 | # Test all error types |
177 | | - flag_not_found = evaluator.get_assignment('missing', {}, 'string', 'test_default') |
| 177 | + flag_not_found = evaluator.get_assignment('missing', 'test_default', {}, 'string') |
178 | 178 | expect(flag_not_found.error_code).to eq('FLAG_UNRECOGNIZED_OR_DISABLED') |
179 | 179 | expect(flag_not_found.value).to eq('test_default') |
180 | 180 | expect(flag_not_found.variant).to be_nil |
181 | 181 | expect(flag_not_found.flag_metadata).to eq({}) |
182 | 182 |
|
183 | | - flag_disabled = evaluator.get_assignment('disabled_flag', {}, 'integer', 'test_default') |
| 183 | + flag_disabled = evaluator.get_assignment('disabled_flag', 'test_default', {}, 'integer') |
184 | 184 | expect(flag_disabled.error_code).to be_nil # Disabled flags are successful cases with nil error_code |
185 | 185 | expect(flag_disabled.error_message).to be_nil # nil for successful disabled cases |
186 | 186 | expect(flag_disabled.reason).to eq('DISABLED') # Disabled reason |
187 | 187 | expect(flag_disabled.value).to eq('test_default') |
188 | 188 | expect(flag_disabled.variant).to be_nil |
189 | 189 | expect(flag_disabled.flag_metadata).to eq({}) |
190 | 190 |
|
191 | | - type_mismatch = evaluator.get_assignment('numeric_flag', {}, 'boolean', 'test_default') |
| 191 | + type_mismatch = evaluator.get_assignment('numeric_flag', 'test_default', {}, 'boolean') |
192 | 192 | expect(type_mismatch.error_code).to eq('TYPE_MISMATCH') |
193 | 193 | expect(type_mismatch.value).to eq('test_default') |
194 | 194 | expect(type_mismatch.variant).to be_nil |
195 | 195 | expect(type_mismatch.flag_metadata).to eq({}) |
196 | 196 | end |
197 | 197 |
|
198 | 198 | it 'provides descriptive error messages matching Rust format' do |
199 | | - result = evaluator.get_assignment('missing_flag', {}, 'string', 'test_default') |
| 199 | + result = evaluator.get_assignment('missing_flag', 'test_default', {}, 'string') |
200 | 200 | expect(result.error_message).to eq('flag is missing in configuration, it is either unrecognized or disabled') |
201 | 201 | expect(result.value).to eq('test_default') |
202 | 202 | expect(result.variant).to be_nil |
203 | 203 | expect(result.flag_metadata).to eq({}) |
204 | 204 |
|
205 | | - type_result = evaluator.get_assignment('numeric_flag', {}, 'boolean', 'test_default') |
| 205 | + type_result = evaluator.get_assignment('numeric_flag', 'test_default', {}, 'boolean') |
206 | 206 | expect(type_result.error_message).to match(/invalid flag type \(expected: .*, found: .*\)/) |
207 | 207 | expect(type_result.value).to eq('test_default') |
208 | 208 | expect(type_result.variant).to be_nil |
|
241 | 241 | evaluation_context['targeting_key'] = targeting_key if targeting_key # Convert camelCase to snake_case |
242 | 242 |
|
243 | 243 | # Execute test case |
244 | | - result = evaluator.get_assignment(flag_key, evaluation_context, expected_type, 'test_default') |
| 244 | + result = evaluator.get_assignment(flag_key, 'test_default', evaluation_context, expected_type) |
245 | 245 |
|
246 | 246 | # Wrap expectations in aggregate_failures for better error reporting |
247 | 247 | aggregate_failures "Test case ##{index + 1}: #{targeting_key} with #{attributes.keys.join(", ")}" do |
|
0 commit comments