require 'spec_helper' RSpec.describe OptimizelyServerSide::Experiment do subject { OptimizelyServerSide::Experiment.new(variation_key = 'variation_key_a') } describe '#applicable_variation' do before do subject.variation_one('variation_key_a') do 'experience a' end subject.variation_two('variation_key_b') do 'experience b' end end context 'when variation_key is present' do it 'should result variation b' do expect(subject.applicable_variation).to eq('experience a') end end context 'when variation_key is not present' do subject { OptimizelyServerSide::Experiment.new(variation_key = '') } it 'should be nil' do expect(subject.applicable_variation).to be_nil end end end describe '#variation_one' do let(:blk) { Proc.new { 'Hello!'} } before do @variation_instance = subject.variation_one('foo', &blk) end it 'returns a variation instance passed' do expect(@variation_instance).to be_kind_of(OptimizelyServerSide::Variation) end it 'returns a key of foo' do expect(@variation_instance.key).to eq('foo') end it 'returns a content with blk ' do expect(@variation_instance.instance_variable_get(:@content)).to eq(blk) end it 'is not primary' do expect(@variation_instance.primary).to be(false) end end describe '#variation_two' do let(:blk) { -> {OpenStruct.new } } before do @variation_instance = subject.variation_two('foo', &blk) end it 'returns a variation instance passed' do expect(@variation_instance).to be_kind_of(OptimizelyServerSide::Variation) end it 'returns a key of foo' do expect(@variation_instance.key).to eq('foo') end it 'returns a content with blk ' do expect(@variation_instance.instance_variable_get(:@content)).to eq(blk) end it 'is not primary' do expect(@variation_instance.primary).to be(false) end end describe '#variation_three' do let(:blk) { Proc.new { 'Hello!'} } before do @variation_instance = subject.variation_three('foo', &blk) end it 'returns a variation instance passed' do expect(@variation_instance).to be_kind_of(OptimizelyServerSide::Variation) end it 'returns a key of foo' do expect(@variation_instance.key).to eq('foo') end it 'returns a content with blk ' do expect(@variation_instance.instance_variable_get(:@content)).to eq(blk) end it 'is not primary' do expect(@variation_instance.primary).to be(false) end end describe '#variation_default' do let(:blk) { -> {'
This is a paragraph.
' } end let(:string_blk) { -> { 'Hello!'} } before do subject.variation_one('foo', &some_method) subject.variation_two('foo_two', &some_html_block) subject.variation_three('foo_three', &string_blk) end it 'has all variations' do expect(subject.instance_variable_get(:@variations)).to have(3).items end it 'has all variations of class Variation' do expect(subject.instance_variable_get(:@variations)).to all(be_an(OptimizelyServerSide::Variation)) end end end describe '#primary_variation' do let(:some_method) { Proc.new {|n| n*2 } } let(:some_html_block) do -> { '