Sha256: 2e545c84fc26ec6680894c96a88c94f4e0b7436bee0ac2d68c802fc24cfcba42

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

require 'spec_helper'

describe VkontakteApi::Client do
  before(:each) do
    @token = stub("Access token")
  end
  
  describe "#initialize" do
    context "without arguments" do
      it "creates a client with a nil access_token" do
        VkontakteApi::Client.new.access_token.should be_nil
      end
    end
    
    context "with a token argument" do
      it "creates a client with a given access_token" do
        client = VkontakteApi::Client.new(@token)
        client.access_token.should == @token
      end
    end
  end
  
  describe "#authorized?" do
    context "with an unauthorized client" do
      it "returns false" do
        VkontakteApi::Client.new.should_not be_authorized
      end
    end
    
    context "with an authorized client" do
      it "returns true" do
        VkontakteApi::Client.new(@token).should be_authorized
      end
    end
  end
  
  describe "#method_missing" do
    before(:each) do
      @resolver = stub("Resolver").as_null_object
      VkontakteApi::Resolver.stub(:new).and_return(@resolver)
      @args = {:field => 'value'}
    end
    
    it "creates a resolver, passing it the access_token" do
      VkontakteApi::Resolver.should_receive(:new).with(:access_token => @token)
      VkontakteApi::Client.new(@token).api_method(@args)
    end
    
    it "delegates to VkontakteApi::Resolver" do
      @resolver.should_receive(:api_method).with(@args)
      VkontakteApi::Client.new(@token).api_method(@args)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vkontakte_api-0.2.1 spec/vkontakte_api/client_spec.rb
vkontakte_api-0.2 spec/vkontakte_api/client_spec.rb
vkontakte_api-0.1 spec/vkontakte_api/client_spec.rb