InfoGrab DocsInfoGrab Docs

실험 테스트

GitLab에서 실험 기능을 RSpec 및 Jest를 사용해 테스트하는 방법을 설명합니다.

RSpec으로 실험 테스트하기 # 실험 작업 과정에서 내장된 RSpec 도구를 사용할 수 있습니다. spec/experiments 내의 파일에 대해서는 자동으로 적용되지만, 다른 파일 및 스펙에서도 포함하려면 :experiment 타입을 명시할 수 있습니다: it "tests experiments nicely", :experiment do end Stub 헬퍼 # stub_experiments 를 사용해 실험을 스텁할 수 있으며, 이는 :experiment 타입 없이도 사용 가능합니다. 실험 이름을 키로, 각 실험이 해석될 variant를 값으로 하는 해시를 전달합니다: # Ensures the experiments named `:example` & `:example2` are both "enabled" and # that each will resolve to the given variant (`:my_variant` and `:control`). stub_experiments(example: :my_variant, example2: :control) experiment(:example) do |e| e.enabled? # => true e.assigned.name # => 'my_variant' end experiment(:example2) do |e| e.enabled? # => true e.assigned.name # => 'control' end 제외, 세그멘테이션 및 동작 매처 # 매처를 사용하여 등록된 동작, 제외 조건, 세그멘테이션 등도 테스트할 수 있습니다. class ExampleExperiment < ApplicationExperiment control { } candidate { '_candidate_' } exclude { context.actor.first_name == 'Richard' } segment(variant: :candidate) { context.actor.username == 'jejacks0n' } end excluded = double(username: 'rdiggitty', first_name: 'Richard') segmented = double(username: 'jejacks0n', first_name: 'Jeremy') # register_behavior matcher expect(experiment(:example)).to register_behavior(:control) expect(experiment(:example)).to register_behavior(:candidate).with('_candidate_') # exclude matcher expect(experiment(:example)).to exclude(actor: excluded) expect(experiment(:example)).not_to exclude(actor: segmented) # segment matcher expect(experiment(:example)).to segment(acto