Module: Gitlab::Experiment::RSpecMatchers

Extended by:
RSpec::Matchers::DSL
Defined in:
lib/gitlab/experiment/rspec.rb

Instance Method Summary collapse

Instance Method Details

#require_experiment(experiment, matcher_name, classes: false) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/gitlab/experiment/rspec.rb', line 84

def require_experiment(experiment, matcher_name, classes: false)
  klass = experiment.class == Class ? experiment : experiment.class
  unless klass <= Gitlab::Experiment
    raise(
      ArgumentError,
      "#{matcher_name} matcher is limited to experiment instances#{classes ? ' and classes' : ''}"
    )
  end

  if experiment == klass && !classes
    raise ArgumentError, "#{matcher_name} matcher requires an instance of an experiment"
  end

  experiment != klass
end