Sha256: 47f2c88bc06cf27585e7686fa3bb020c140445445337b22409b16702d629bf8f

Contents?: true

Size: 1.43 KB

Versions: 9

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'

RSpec.describe OptimizelyServerSide::Support do

  class MyEventDispatcher

    def dispatch_event(url,params)
      puts "Do nothing with #{url} and #{params}"
    end
  end
  class FakeKlass

    include OptimizelyServerSide::Support


    def some_klass_method

      experiment('foo_experiment_key') do |config|

        config.variation_one('variation_one') do
          'Experience one'
        end

        config.variation_two('variation_two') do
          'Experience two'
        end

      end
    end
  end


  describe '#experiment' do

    subject { FakeKlass.new }

    context 'everything is good' do


      before do
        allow(subject).to receive(:optimizely_sdk_project_instance).and_return('variation_one')
      end

      it { expect(subject.some_klass_method).to eq('Experience one')}
    end


    context 'when a fatal error has happened' do

      let(:response) do
        '{
            "experiments": [],
            "version": "1",
            "audiences": [],
            "dimensions": [],
            "groups": [],
            "projectId": "5960232316",
            "accountId": "5955320306",
            "events": [],
            "revision": "30"
          }'
      end

      before do
        stub_request(:get, "https://cdn.optimizely.com/json/5960232316.json")
        .to_return(body: response, status: 500)
      end


      it { expect(subject.some_klass_method).to be_nil }
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
optimizely_server_side-0.0.12 spec/optimizely_server_side/helpers/support_spec.rb
optimizely_server_side-0.0.11 spec/optimizely_server_side/helpers/support_spec.rb
optimizely_server_side-0.0.10 spec/optimizely_server_side/helpers/support_spec.rb
optimizely_server_side-0.0.9 spec/optimizely_server_side/helpers/support_spec.rb
optimizely_server_side-0.0.8 spec/optimizely_server_side/helpers/support_spec.rb
optimizely_server_side-0.0.7 spec/optimizely_server_side/helpers/support_spec.rb
optimizely_server_side-0.0.6 spec/optimizely_server_side/helpers/support_spec.rb
optimizely_server_side-0.0.5 spec/optimizely_server_side/helpers/support_spec.rb
optimizely_server_side-0.0.4 spec/optimizely_server_side/helpers/support_spec.rb