Sha256: 8142b4420f101674ba169037d1b435ac94512b0a473cc50d04cc8c190986560f

Contents?: true

Size: 1.32 KB

Versions: 23

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

describe Rubix::Connection do

  before do
    
    @mock_server   = mock("Net::HTTP instance")
    Net::HTTP.stub!(:new).and_return(@mock_server)
    
    @mock_response = mock("Net::HTTP::Response instance")
    @mock_server.stub!(:request).and_return(@mock_response)
    @mock_response.stub!(:code).and_return('200')
    

    @good_auth_response = '{"result": "auth_token"}'
    @blah_response      = '{"result": "bar"}'

    @mock_response.stub!(:body).and_return(@blah_response)
    
    @connection = Rubix::Connection.new('localhost/api.php', 'username', 'password')
  end

  it "should attempt to authorize itself without being asked" do
    @connection.should_receive(:authorize!)
    @connection.request('foobar', {})
  end

  it "should not repeatedly authorize itself" do
    @mock_response.stub!(:body).and_return(@good_auth_response, @blah_response, @blah_response)
    @connection.request('foobar', {})
    @connection.should_not_receive(:authorize!)
    @connection.request('foobar', {})
  end

  it "should increment its request ID" do
    @mock_response.stub!(:body).and_return(@good_auth_response, @blah_response, @blah_response)
    @connection.request('foobar', {})
    @connection.request('foobar', {})
    @connection.request_id.should == 3 # it's the number used for the *next* request
  end

end
  

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rubix-0.4.0 spec/rubix/connection_spec.rb
rubix-0.3.1 spec/rubix/connection_spec.rb
rubix-0.3.0 spec/rubix/connection_spec.rb
rubix-0.2.1 spec/rubix/connection_spec.rb
rubix-0.2.0 spec/rubix/connection_spec.rb
rubix-0.1.5 spec/rubix/connection_spec.rb
rubix-0.1.4 spec/rubix/connection_spec.rb
rubix-0.1.3 spec/rubix/connection_spec.rb
rubix-0.1.2 spec/rubix/connection_spec.rb
rubix-0.1.1 spec/rubix/connection_spec.rb
rubix-0.1.0 spec/rubix/connection_spec.rb
rubix-0.0.12 spec/rubix/connection_spec.rb
rubix-0.0.11 spec/rubix/connection_spec.rb
rubix-0.0.10 spec/rubix/connection_spec.rb
rubix-0.0.9 spec/rubix/connection_spec.rb
rubix-0.0.8 spec/rubix/connection_spec.rb
rubix-0.0.7 spec/rubix/connection_spec.rb
rubix-0.0.6 spec/rubix/connection_spec.rb
rubix-0.0.5 spec/rubix/connection_spec.rb
rubix-0.0.4 spec/rubix/connection_spec.rb