Module: RSpec::Determinator::DSL

Defined in:
lib/rspec/determinator.rb

Instance Method Summary collapse

Instance Method Details

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

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)

Parameters:

  • name (String, Symbol)

    The name of the Feature Flag or Experiment to mock

  • outcome (Boolean, String, Symbol)

    The outcome which should be supplied. Will look up an example variable if a Symbol is given.

  • :only_for (Hash, Symbol)

    The constraints that must be matched exactly in order for the determination to be applied.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rspec/determinator.rb', line 33

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