|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | # |
4 | | -# Copyright 2019, Optimizely and contributors |
| 4 | +# Copyright 2019, 2023, Optimizely and contributors |
5 | 5 | # |
6 | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 7 | # you may not use this file except in compliance with the License. |
|
27 | 27 |
|
28 | 28 | describe 'evaluate' do |
29 | 29 | it 'should return true for a leaf condition when the leaf condition evaluator returns true' do |
30 | | - leaf_callback = ->(_condition) { return true } |
| 30 | + leaf_callback = ->(_condition) { true } |
31 | 31 | expect(Optimizely::ConditionTreeEvaluator.evaluate(@browser_condition, leaf_callback)).to be true |
32 | 32 | end |
33 | 33 |
|
34 | 34 | it 'should return false for a leaf condition when the leaf condition evaluator returns false' do |
35 | | - leaf_callback = ->(_condition) { return false } |
| 35 | + leaf_callback = ->(_condition) { false } |
36 | 36 | expect(Optimizely::ConditionTreeEvaluator.evaluate(@browser_condition, leaf_callback)).to be false |
37 | 37 | end |
38 | 38 | end |
39 | 39 |
|
40 | 40 | describe 'and evaluation' do |
41 | 41 | it 'should return true when ALL conditions evaluate to true' do |
42 | | - leaf_callback = ->(_condition) { return true } |
| 42 | + leaf_callback = ->(_condition) { true } |
43 | 43 | expect(Optimizely::ConditionTreeEvaluator.evaluate(['and', @browser_condition, @device_condition], leaf_callback)).to be true |
44 | 44 | end |
45 | 45 |
|
|
51 | 51 |
|
52 | 52 | describe 'nil handling' do |
53 | 53 | it 'should return nil when all operands evaluate to nil' do |
54 | | - leaf_callback = ->(_condition) { return nil } |
| 54 | + leaf_callback = ->(_condition) { nil } |
55 | 55 | expect(Optimizely::ConditionTreeEvaluator.evaluate(['and', @browser_condition, @device_condition], leaf_callback)).to eq(nil) |
56 | 56 | end |
57 | 57 |
|
|
83 | 83 |
|
84 | 84 | describe 'or evaluation' do |
85 | 85 | it 'should return false if all conditions evaluate to false' do |
86 | | - leaf_callback = ->(_condition) { return false } |
| 86 | + leaf_callback = ->(_condition) { false } |
87 | 87 | expect(Optimizely::ConditionTreeEvaluator.evaluate(['or', @browser_condition, @device_condition], leaf_callback)).to be false |
88 | 88 | end |
89 | 89 |
|
|
95 | 95 |
|
96 | 96 | describe 'nil handling' do |
97 | 97 | it 'should return nil when all operands evaluate to nil' do |
98 | | - leaf_callback = ->(_condition) { return nil } |
| 98 | + leaf_callback = ->(_condition) { nil } |
99 | 99 | expect(Optimizely::ConditionTreeEvaluator.evaluate(['or', @browser_condition, @device_condition], leaf_callback)).to eq(nil) |
100 | 100 | end |
101 | 101 |
|
|
127 | 127 |
|
128 | 128 | describe 'not evaluation' do |
129 | 129 | it 'should return true if the condition evaluates to false' do |
130 | | - leaf_callback = ->(_condition) { return false } |
| 130 | + leaf_callback = ->(_condition) { false } |
131 | 131 | expect(Optimizely::ConditionTreeEvaluator.evaluate(['not', @browser_condition], leaf_callback)).to be true |
132 | 132 | end |
133 | 133 |
|
134 | 134 | it 'should return false if the condition evaluates to true' do |
135 | | - leaf_callback = ->(_condition) { return true } |
| 135 | + leaf_callback = ->(_condition) { true } |
136 | 136 | expect(Optimizely::ConditionTreeEvaluator.evaluate(['not', @browser_condition], leaf_callback)).to be false |
137 | 137 | end |
138 | 138 |
|
139 | 139 | it 'should return the result of negating the first condition, and ignore any additional conditions' do |
140 | | - leaf_callback = ->(id) { return id == '1' } |
| 140 | + leaf_callback = ->(id) { id == '1' } |
141 | 141 | expect(Optimizely::ConditionTreeEvaluator.evaluate(%w[not 1 2 1], leaf_callback)).to be false |
142 | 142 |
|
143 | | - leaf_callback2 = ->(id) { return id == '2' } |
| 143 | + leaf_callback2 = ->(id) { id == '2' } |
144 | 144 | expect(Optimizely::ConditionTreeEvaluator.evaluate(%w[not 1 2 1], leaf_callback2)).to be true |
145 | 145 |
|
146 | | - leaf_callback3 = ->(id) { return id == '1' ? nil : id == '3' } |
| 146 | + leaf_callback3 = ->(id) { id == '1' ? nil : id == '3' } |
147 | 147 | expect(Optimizely::ConditionTreeEvaluator.evaluate(%w[not 1 2 3], leaf_callback3)).to eq(nil) |
148 | 148 | end |
149 | 149 |
|
150 | 150 | describe 'nil handling' do |
151 | 151 | it 'should return nil when operand evaluates to nil' do |
152 | | - leaf_callback = ->(_condition) { return nil } |
| 152 | + leaf_callback = ->(_condition) { nil } |
153 | 153 | expect(Optimizely::ConditionTreeEvaluator.evaluate(['not', @browser_condition, @device_condition], leaf_callback)).to eq(nil) |
154 | 154 | end |
155 | 155 |
|
156 | 156 | it 'should return nil when there are no operands' do |
157 | | - leaf_callback = ->(_condition) { return nil } |
| 157 | + leaf_callback = ->(_condition) { nil } |
158 | 158 | expect(Optimizely::ConditionTreeEvaluator.evaluate(['not'], leaf_callback)).to eq(nil) |
159 | 159 | end |
160 | 160 | end |
|
166 | 166 | allow(leaf_callback).to receive(:call).and_return(true, false) |
167 | 167 | expect(Optimizely::ConditionTreeEvaluator.evaluate([@browser_condition, @device_condition], leaf_callback)).to be true |
168 | 168 |
|
169 | | - leaf_callback = ->(_condition) { return false } |
| 169 | + leaf_callback = ->(_condition) { false } |
170 | 170 | allow(leaf_callback).to receive(:call).and_return(false, true) |
171 | 171 | expect(Optimizely::ConditionTreeEvaluator.evaluate([@browser_condition, @device_condition], leaf_callback)).to be true |
172 | 172 | end |
|
0 commit comments