Module: Experimental::Test

Included in:
RSpec, Unit
Defined in:
lib/experimental/test.rb,
lib/experimental/test/unit.rb,
lib/experimental/test/rspec.rb

Overview

Test helpers for applications that use Experimental.

For popular test frameworks, simply require the appropriate experimental/test/*.rb file. If those doesn’t cover you, check one of those to see how to hook up your favorite framework.

Defined Under Namespace

Modules: RSpec, Unit

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.initializeObject

Call this once to initialize Experimental for your test suite.

Calling it again isn’t harmful, just unnecessary.



11
12
13
14
15
16
# File 'lib/experimental/test.rb', line 11

def self.initialize
  return if @initialized
  @initial_source = Experimental.source
  Experimental.source = Experimental::Source::Configuration.new
  @initialized = true
end

.setupObject

Call this before each test. It provides a deterministic default: all subjects are out of all experiments. Opt subjects into experiments using #set_experimental_bucket.



21
22
23
24
# File 'lib/experimental/test.rb', line 21

def self.setup
  Experimental.overrides.reset
  Experimental.overrides.set_default(nil)
end

.teardownObject



26
27
28
29
# File 'lib/experimental/test.rb', line 26

def self.teardown
  Experimental.source = @initial_source
  @initialized = false
end

Instance Method Details

#set_experimental_bucket(subject, experiment_name, bucket) ⇒ Object

Force the given subject into the given bucket of the given experiment.

If bucket is nil, exclude the user from the experiment.



34
35
36
# File 'lib/experimental/test.rb', line 34

def set_experimental_bucket(subject, experiment_name, bucket)
  Experimental.overrides[subject, experiment_name] = bucket
end