Sha256: 4bfbcd9b2dd19fd2812e0cf01881bf1262bb6a00ea2147d83e6be70ada047a58

Contents?: true

Size: 1.53 KB

Versions: 10

Compression:

Stored size: 1.53 KB

Contents

require 'spec/spec_helper'

describe RPXNow::Api do
  describe 'ssl cert' do
    it "has an absolute path" do
      RPXNow::Api::SSL_CERT[0..0].should == '/' #start with '/'
    end

    it "exists" do
      File.read(RPXNow::Api::SSL_CERT).to_s.should_not be_empty
    end
  end

  describe :parse_response do
    it "parses json when status is ok" do
      response = mock(:code=>'200', :body=>%Q({"stat":"ok","data":"xx"}))
      RPXNow::Api.send(:parse_response, response)['data'].should == "xx"
    end

    it "raises when there is a communication error" do
      response = stub(:code=>'200', :body=>%Q({"err":"wtf","stat":"ok"}))
      lambda{
        RPXNow::Api.send(:parse_response,response)
      }.should raise_error(RPXNow::ApiError)
    end

    it "raises when service has downtime" do
      response = stub(:code=>'200', :body=>%Q({"err":{"code":-1},"stat":"ok"}))
      lambda{
        RPXNow::Api.send(:parse_response,response)
      }.should raise_error(RPXNow::ServiceUnavailableError)
    end

    it "raises when service is down" do
      response = stub(:code=>'400',:body=>%Q({"stat":"err"}))
      lambda{
        RPXNow::Api.send(:parse_response,response)
      }.should raise_error(RPXNow::ServiceUnavailableError)
    end
  end

  describe :request_object do
    it "converts symbols to string keys" do
      mock = ''
      mock.should_receive(:form_data=).with([['symbol', 'value']])
      Net::HTTP::Post.should_receive(:new).and_return(mock)
      RPXNow::Api.send(:request_object, 'something', :symbol=>'value')
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
kent-rpx_now-0.6.11 spec/rpx_now/api_spec.rb
rpx_now-0.6.11 spec/rpx_now/api_spec.rb
rpx_now-0.6.10 spec/rpx_now/api_spec.rb
rpx_now-0.6.9 spec/rpx_now/api_spec.rb
rpx_now-0.6.8 spec/rpx_now/api_spec.rb
rpx_now-0.6.7 spec/rpx_now/api_spec.rb
rpx_now-0.6.6 spec/rpx_now/api_spec.rb
spyou_rpx_now-0.6.6 spec/rpx_now/api_spec.rb
rpx_now-0.6.5 spec/rpx_now/api_spec.rb
rpx_now-0.6.4 spec/rpx_now/api_spec.rb