module RSpec::Determinator::DSL

Public Instance Methods

forced_determination(name, outcome, bucket_type: 'single', only_for: {}) click to toggle source

Ensure that for the duration of the example all determinations made for the given experiment or feature flag will have the given outcome (but only if the constraints specified are met exactly).

If `outcome` or `only_for` are Symbols then the example-scoped variable of that name will be referenced (ie. those variables created by `let` declarations)

@param [String,Symbol] name The name of the Feature Flag or Experiment to mock @param [Boolean,String,Symbol] outcome The outcome which should be supplied. Will look up an example variable if a Symbol is given. @param [Hash,Symbol] :only_for The constraints that must be matched exactly in order for the determination to be applied.

# File lib/rspec/determinator.rb, line 36
def forced_determination(name, outcome, bucket_type: 'single', only_for: {})
  before do
    outcome = send(outcome) if outcome.is_a?(Symbol)
    only_for = send(only_for) if only_for.is_a?(Symbol)

    ::RSpec::Determinator::FakeDeterminator.new(fake_retriever).mock_result(
      name,
      outcome,
      bucket_type: bucket_type,
      only_for: only_for
    )
  end
end