Class: RSpec::Determinator::FakeDeterminator

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/determinator.rb

Constant Summary collapse

VALID_BUCKET_TYPES =
%w{ id guid single }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(in_memory_retriever) ⇒ FakeDeterminator

Returns a new instance of FakeDeterminator.



50
51
52
# File 'lib/rspec/determinator.rb', line 50

def initialize(in_memory_retriever)
  @retriever = in_memory_retriever
end

Instance Method Details

#mock_result(name, outcome, bucket_type: 'single', only_for: {}) ⇒ Object



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
# File 'lib/rspec/determinator.rb', line 56

def mock_result(name, outcome, bucket_type: 'single', only_for: {})
  if !VALID_BUCKET_TYPES.include?(bucket_type)
    raise ArgumentError.new("bad bucket type #{bucket_type}, expected one of: #{VALID_BUCKET_TYPES.join(' ')}")
  end

  active = !!outcome
  variants = case outcome
             when true, false then
               []
             else
               { outcome => 1 }
             end
  target_group = ::Determinator::TargetGroup.new(
    rollout: 65_536,
    constraints: only_for.map { |key, value| [key.to_s, Array(value).map(&:to_s)] }.to_h
  )

  feature = ::Determinator::Feature.new(
    name: name.to_s,
    identifier: name.to_s,
    bucket_type: bucket_type,
    active: active,
    variants: variants,
    target_groups: [target_group]
  )

  @retriever.store(feature)
end