Skip to content

Commit 1712fc7

Browse files
committed
Fix lint issues
1 parent 67f2e13 commit 1712fc7

File tree

2 files changed

+55
-73
lines changed

2 files changed

+55
-73
lines changed

spec/decision_service_holdout_spec.rb

Lines changed: 54 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@
110110
applicable_holdout = config_with_holdouts.holdouts.find do |holdout|
111111
# Global holdout (empty/nil includedFlags) that doesn't exclude this flag
112112
(holdout['includedFlags'].nil? || holdout['includedFlags'].empty?) &&
113-
!(holdout['excludedFlags']&.include?(feature_flag['id']))
113+
!holdout['excludedFlags']&.include?(feature_flag['id'])
114114
end
115115
end
116116

117-
expect(applicable_holdout).not_to be_nil, "No applicable holdout found for boolean_feature"
117+
expect(applicable_holdout).not_to be_nil, 'No applicable holdout found for boolean_feature'
118118

119119
# Mock holdout as inactive
120120
original_status = applicable_holdout['status']
@@ -364,9 +364,8 @@
364364

365365
expect(decision_result).not_to be_nil
366366

367-
if decision_result.decision && decision_result.decision.source == Optimizely::DecisionService::DECISION_SOURCES['HOLDOUT']
368-
expect(decision_service_with_holdouts).not_to have_received(:get_variation_for_feature_experiment)
369-
end
367+
decision_result.decision && decision_result.decision.source == Optimizely::DecisionService::DECISION_SOURCES['HOLDOUT'] && holdout_decisions << decision_result
368+
expect(decision_service_with_holdouts).not_to have_received(:get_variation_for_feature_experiment)
370369
end
371370

372371
it 'should evaluate global holdouts for all flags' do
@@ -611,7 +610,7 @@
611610
error_handler
612611
)
613612
end
614-
613+
615614
let(:optimizely_with_mocked_events) do
616615
Optimizely::Project.new(
617616
datafile: OptimizelySpec::CONFIG_BODY_WITH_HOLDOUTS_JSON,
@@ -630,18 +629,18 @@
630629
# Use a specific user ID that will be bucketed into a holdout
631630
# This is deterministic based on the bucketing algorithm
632631
test_user_id = 'user_bucketed_into_holdout'
633-
632+
634633
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
635634
expect(feature_flag).not_to be_nil, "Feature flag 'boolean_feature' should exist"
636-
635+
637636
user_attributes = {}
638637

639638
allow(spy_event_processor).to receive(:process)
640639

641640
user_context = optimizely_with_mocked_events.create_user_context(test_user_id, user_attributes)
642641
decision = user_context.decide(feature_flag['key'])
643642

644-
expect(decision).not_to be_nil, "Decision should not be nil"
643+
expect(decision).not_to be_nil, 'Decision should not be nil'
645644

646645
actual_holdout = config_with_holdouts.holdouts&.find { |h| h['key'] == decision.rule_key }
647646

@@ -651,11 +650,9 @@
651650

652651
holdout_variation = actual_holdout['variations'].find { |v| v['key'] == decision.variation_key }
653652

654-
expect(holdout_variation).not_to be_nil,
655-
"Variation '#{decision.variation_key}' should be from the chosen holdout '#{actual_holdout['key']}'"
653+
expect(holdout_variation).not_to be_nil, "Variation '#{decision.variation_key}' should be from the chosen holdout '#{actual_holdout['key']}'"
656654

657-
expect(decision.enabled).to eq(holdout_variation['featureEnabled']),
658-
"Enabled flag should match holdout variation's featureEnabled value"
655+
expect(decision.enabled).to eq(holdout_variation['featureEnabled']), "Enabled flag should match holdout variation's featureEnabled value"
659656

660657
expect(spy_event_processor).to have_received(:process)
661658
.with(instance_of(Optimizely::ImpressionEvent))
@@ -672,10 +669,10 @@
672669

673670
it 'should not send impression event when DISABLE_DECISION_EVENT option is used' do
674671
test_user_id = 'user_bucketed_into_holdout'
675-
672+
676673
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
677674
expect(feature_flag).not_to be_nil
678-
675+
679676
user_attributes = {}
680677

681678
allow(spy_event_processor).to receive(:process)
@@ -686,7 +683,7 @@
686683
[Optimizely::Decide::OptimizelyDecideOption::DISABLE_DECISION_EVENT]
687684
)
688685

689-
expect(decision).not_to be_nil, "Decision should not be nil"
686+
expect(decision).not_to be_nil, 'Decision should not be nil'
690687

691688
chosen_holdout = config_with_holdouts.holdouts&.find { |h| h['key'] == decision.rule_key }
692689

@@ -703,96 +700,81 @@
703700
describe '#decide with holdout notification content' do
704701
it 'should send correct notification content for holdout decision' do
705702
captured_notifications = []
706-
707-
notification_callback = lambda do |notification_type, user_id, user_attributes, decision_info|
703+
704+
notification_callback = lambda do |_notification_type, _user_id, _user_attributes, decision_info|
708705
captured_notifications << decision_info.dup
709706
end
710-
707+
711708
optimizely_with_mocked_events.notification_center.add_notification_listener(
712709
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:DECISION],
713710
notification_callback
714711
)
715-
712+
716713
# Mock the decision service to return a holdout decision
717714
holdout = config_with_holdouts.holdouts.first
718-
expect(holdout).not_to be_nil, "Should have at least one holdout configured"
719-
715+
expect(holdout).not_to be_nil, 'Should have at least one holdout configured'
716+
720717
holdout_variation = holdout['variations'].first
721-
expect(holdout_variation).not_to be_nil, "Holdout should have at least one variation"
722-
718+
expect(holdout_variation).not_to be_nil, 'Holdout should have at least one variation'
719+
723720
# Create a holdout decision
724721
holdout_decision = Optimizely::DecisionService::Decision.new(
725722
holdout,
726723
holdout_variation,
727724
Optimizely::DecisionService::DECISION_SOURCES['HOLDOUT']
728725
)
729-
726+
730727
holdout_decision_result = Optimizely::DecisionService::DecisionResult.new(
731728
holdout_decision,
732729
false,
733730
[]
734731
)
735-
732+
736733
# Mock get_variations_for_feature_list to return holdout decision
737734
allow_any_instance_of(Optimizely::DecisionService).to receive(:get_variations_for_feature_list)
738735
.and_return([holdout_decision_result])
739-
736+
740737
test_user_id = 'test_user'
741-
user_attributes = { 'country' => 'us' }
742-
738+
user_attributes = {'country' => 'us'}
739+
743740
user_context = optimizely_with_mocked_events.create_user_context(test_user_id, user_attributes)
744-
decision = user_context.decide('boolean_feature')
745-
746-
expect(captured_notifications.length).to eq(1),
747-
"Should have captured exactly one decision notification"
748-
741+
742+
expect(captured_notifications.length).to eq(1), 'Should have captured exactly one decision notification'
743+
749744
notification = captured_notifications.first
750745
rule_key = notification[:rule_key]
751-
752-
expect(rule_key).to eq(holdout['key']), "RuleKey should match holdout key"
753-
746+
747+
expect(rule_key).to eq(holdout['key']), 'RuleKey should match holdout key'
748+
754749
# Verify holdout notification structure
755-
expect(notification).to have_key(:flag_key),
756-
"Holdout notification should contain flag_key"
757-
expect(notification).to have_key(:enabled),
758-
"Holdout notification should contain enabled flag"
759-
expect(notification).to have_key(:variation_key),
760-
"Holdout notification should contain variation_key"
761-
expect(notification).to have_key(:experiment_id),
762-
"Holdout notification should contain experiment_id"
763-
expect(notification).to have_key(:variation_id),
764-
"Holdout notification should contain variation_id"
765-
750+
expect(notification).to have_key(:flag_key), 'Holdout notification should contain flag_key'
751+
expect(notification).to have_key(:enabled), 'Holdout notification should contain enabled flag'
752+
expect(notification).to have_key(:variation_key), 'Holdout notification should contain variation_key'
753+
expect(notification).to have_key(:experiment_id), 'Holdout notification should contain experiment_id'
754+
expect(notification).to have_key(:variation_id), 'Holdout notification should contain variation_id'
755+
766756
flag_key = notification[:flag_key]
767-
expect(flag_key).to eq('boolean_feature'), "FlagKey should match the requested flag"
768-
757+
expect(flag_key).to eq('boolean_feature'), 'FlagKey should match the requested flag'
758+
769759
experiment_id = notification[:experiment_id]
770-
expect(experiment_id).to eq(holdout['id']),
771-
"ExperimentId in notification should match holdout ID"
760+
expect(experiment_id).to eq(holdout['id']), 'ExperimentId in notification should match holdout ID'
772761

773762
variation_id = notification[:variation_id]
774-
expect(variation_id).to eq(holdout_variation['id']),
775-
"VariationId should match holdout variation ID"
776-
763+
expect(variation_id).to eq(holdout_variation['id']), 'VariationId should match holdout variation ID'
764+
777765
variation_key = notification[:variation_key]
778-
expect(variation_key).to eq(holdout_variation['key']),
779-
"VariationKey in notification should match holdout variation key"
780-
766+
expect(variation_key).to eq(holdout_variation['key']), 'VariationKey in notification should match holdout variation key'
767+
781768
enabled = notification[:enabled]
782-
expect(enabled).not_to be_nil, "Enabled flag should be present in notification"
783-
expect(enabled).to eq(holdout_variation['featureEnabled']),
784-
"Enabled flag should match holdout variation's featureEnabled value"
785-
786-
expect(config_with_holdouts.feature_flag_key_map).to have_key(flag_key),
787-
"FlagKey '#{flag_key}' should exist in config"
788-
789-
expect(notification).to have_key(:variables),
790-
"Notification should contain variables"
791-
expect(notification).to have_key(:reasons),
792-
"Notification should contain reasons"
793-
expect(notification).to have_key(:decision_event_dispatched),
794-
"Notification should contain decision_event_dispatched"
769+
expect(enabled).not_to be_nil, 'Enabled flag should be present in notification'
770+
expect(enabled).to eq(holdout_variation['featureEnabled']), "Enabled flag should match holdout variation's featureEnabled value"
771+
772+
expect(config_with_holdouts.feature_flag_key_map).to have_key(flag_key), "FlagKey '#{flag_key}' should exist in config"
773+
774+
expect(notification).to have_key(:variables), 'Notification should contain variables'
775+
expect(notification).to have_key(:reasons), 'Notification should contain reasons'
776+
expect(notification).to have_key(:decision_event_dispatched), 'Notification should contain decision_event_dispatched'
795777
end
796778
end
797779
end
798-
end
780+
end

spec/spec_params.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@ module OptimizelySpec
19561956
'featureEnabled' => true
19571957
},
19581958
{
1959-
'id' => 'var_2',
1959+
'id' => 'var_2',
19601960
'key' => 'treatment',
19611961
'featureEnabled' => true
19621962
}

0 commit comments

Comments
 (0)