Sha256: ff377097c651c549e47bbade115bd934d362f54ed9291c3bb53be1657f749a47

Contents?: true

Size: 1.7 KB

Versions: 6

Compression:

Stored size: 1.7 KB

Contents

require './spec/spec_helper'

# Test client implemenations for multi client switching
module SparkApi
  def self.test_client_a
    Thread.current[:test_client_a] ||= Client.new(:api_key => "a")
  end
  def self.test_client_b
    Client.new(:api_key => "b")
  end
  def self.test_client_c
    Client.new(:api_key => "c")
  end
end

describe SparkApi::MultiClient do
  it "should activate a client implemenation when activate()" do
    SparkApi.activate(:test_client_a)
    SparkApi.client.api_key.should eq('a')
    SparkApi.activate(:test_client_b)
    SparkApi.client.api_key.should eq('b')
    SparkApi.activate(:test_client_c)
    SparkApi.client.api_key.should eq('c')
    SparkApi.activate(:test_client_a)
    SparkApi.client.api_key.should eq('a')
  end
  it "should fail to activate symbols that do not have implementations" do
    expect { SparkApi.activate(:test_client_d) }.to raise_error(ArgumentError)
  end
  
  it "should temporarily activate a client implemenation when activate() block" do
    SparkApi.activate(:test_client_a)
    SparkApi.client.api_key.should eq('a')
    SparkApi.activate(:test_client_b) do
      SparkApi.client.api_key.should eq('b')
    end
    SparkApi.client.api_key.should eq('a')
    expect do
      SparkApi.activate(:test_client_c) do
        SparkApi.client.api_key.should eq('c')
        raise "OH MY GOODNESS I BLEW UP!!!"
      end
    end.to raise_error
    SparkApi.client.api_key.should eq('a')
  end

  context "yaml" do
    it "should activate a client implemenation when activate()" do
      SparkApi::Configuration::YamlConfig.stub(:config_path) { "spec/config/spark_api" }
      SparkApi.activate(:test_key)
      SparkApi.client.api_key.should eq('demo_key')
    end
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spark_api-1.1.1 spec/unit/spark_api/multi_client_spec.rb
spark_api-1.1.0 spec/unit/spark_api/multi_client_spec.rb
spark_api-1.0.4 spec/unit/spark_api/multi_client_spec.rb
spark_api-1.0.2 spec/unit/spark_api/multi_client_spec.rb
spark_api-1.0.1 spec/unit/spark_api/multi_client_spec.rb
spark_api-1.0.0 spec/unit/spark_api/multi_client_spec.rb