Sha256: 5e8237e6b712a80e0eb68b6e93c3d128932791cf78371167d1a73d1914e7f1fd

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'

describe StackOverflow::Client do
  before do
    @client = StackOverflow::Client.new
  end

  it 'should provide the api method path with its parameters' do
    url1 = @client.api_method_path('/foo/bar')
    url1.should == '/foo/bar/'

    url2 = @client.api_method_path('/foo/:bar/', :bar => 2)
    url2.should == '/foo/2/'

    url3 = @client.api_method_path('/foo/:bar/eggs', :bar => 'fried')
    url3.should == '/foo/fried/eggs/'
  end

  it 'should provide the full url for the api method' do 
    url = @client.api_method_url('/foo/bar', :query => { :name => 'smith', :lastname => 'smith'})
    url.should == @client.root_path + '/foo/bar/?lastname=smith&name=smith'

    url2 = @client.api_method_url('/foo/:bar', :bar => 2)
    url2.should == @client.root_path + '/foo/2/'

    url3 = @client.api_method_url('/foo/:bar/eggs', :bar => :fried, :query => { :with => 'bacon'} )
    url3.should == @client.root_path + '/foo/fried/eggs/?with=bacon'
  end

  describe 'when using #config for configuration setup' do
    before do
      @client = StackOverflow::Client.new
      @old_url = @client.url 

      StackOverflow::Client.config do |options|
        options.url = 'http://test.it'
        options.api_version = '666'
        options.api_key = 'key1234'
      end
    end

    after do
      StackOverflow::Client.config do |options|
        options.url = @old_url
      end
    end

    it 'should modify the api url' do
      StackOverflow::Statistics.client.url.should == 'http://test.it/'
    end

    it 'should modify the api version' do
      StackOverflow::Statistics.client.api_version.should == '666'
    end

    it 'should modify the api key' do
      StackOverflow::Statistics.client.api_key.should == 'key1234'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pilha-0.1.5 spec/pilha/stack_overflow/stack_overflow_spec.rb
pilha-0.1.3 spec/pilha/stack_overflow/stack_overflow_spec.rb
pilha-0.1.2 spec/pilha/stack_overflow/stack_overflow_spec.rb