class RSpec::Determinator::FakeDeterminator

Constants

VALID_BUCKET_TYPES

Public Class Methods

new(in_memory_retriever) click to toggle source
# File lib/rspec/determinator.rb, line 53
def initialize(in_memory_retriever)
  @retriever = in_memory_retriever
end

Public Instance Methods

mock_result(name, outcome, bucket_type: 'single', only_for: {}) click to toggle source
# File lib/rspec/determinator.rb, line 59
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