Sha256: f02d0373473ef496d47bc6de1b88367a531fd66ac10ae3facafc1ee9d228e846

Contents?: true

Size: 1.74 KB

Versions: 6

Compression:

Stored size: 1.74 KB

Contents

require './spec/spec_helper'

# Test client implemenations for multi client switching
module FlexmlsApi
  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 FlexmlsApi::MultiClient do
  it "should activate a client implemenation when activate()" do
    FlexmlsApi.activate(:test_client_a)
    FlexmlsApi.client.api_key.should eq('a')
    FlexmlsApi.activate(:test_client_b)
    FlexmlsApi.client.api_key.should eq('b')
    FlexmlsApi.activate(:test_client_c)
    FlexmlsApi.client.api_key.should eq('c')
    FlexmlsApi.activate(:test_client_a)
    FlexmlsApi.client.api_key.should eq('a')
  end
  it "should fail to activate symbols that do not have implementations" do
    expect { FlexmlsApi.activate(:test_client_d) }.to raise_error(ArgumentError)
  end
  
  it "should temporarily activate a client implemenation when activate() block" do
    FlexmlsApi.activate(:test_client_a)
    FlexmlsApi.client.api_key.should eq('a')
    FlexmlsApi.activate(:test_client_b) do
      FlexmlsApi.client.api_key.should eq('b')
    end
    FlexmlsApi.client.api_key.should eq('a')
    expect do
      FlexmlsApi.activate(:test_client_c) do
        FlexmlsApi.client.api_key.should eq('c')
        raise "OH MY GOODNESS I BLEW UP!!!"
      end
    end.to raise_error
    FlexmlsApi.client.api_key.should eq('a')
  end

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

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
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~
flexmls_api-0.7.3 spec/unit/flexmls_api/multi_client_spec.rb
flexmls_api-0.7.5 spec/unit/flexmls_api/multi_client_spec.rb
flexmls_api-0.7.0 spec/unit/flexmls_api/multi_client_spec.rb