Sha256: 3370db2d57eab7706cb105e45daefc26a9a3d33de96e5ea47cba3c346e930e47

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

FakeWeb.register_uri :get, 'http://api.comcetera.com/npl?user=username&pass=password&msisdn=31612345678', :body=> <<-MSG
QUERYOK
31612345678 12345
ENDBATCH
MSG
FakeWeb.register_uri :get, 'http://api.comcetera.com/npl?user=username&pass=password&msisdn=31612345621', :body=> <<-MSG
QUERYOK
31612345621 ERR21
ENDBATCH
MSG

describe "Comcetera" do
  before(:all) do
    Comcetera.username = "username"
    Comcetera.password = "password"
  end

  describe "detect" do
    it "should return a new Comcetera instance" do
      @comcetera = Comcetera.detect(31612345678)
      @comcetera.should be_instance_of(Comcetera)
    end

    it "should retry after a timeout and return nil when it still fails" do
      3.times {Timeout.should_receive(:timeout).with(2).and_raise(Timeout::Error)}
      @comcetera = Comcetera.detect(31612345678)
      @comcetera.should be_nil
    end

    describe "the returned Comcetera instance" do
      before(:each) do
        @comcetera = Comcetera.detect(31612345678)
      end

      it "should contain the returned operator code" do
        @comcetera.operator_code.should == "12345"
      end

      it "should contain the returned msisdn" do
        @comcetera.msisdn.should == "31612345678"
      end
    end
    
    it "should return an instance with error code and debug info when no operator code is returned" do
      @comcetera = Comcetera.detect(31612345621)
      @comcetera.operator_code.should be_nil
      @comcetera.error_code.should == "ERR21"
      @comcetera.debug.should == <<-MSG
QUERYOK
31612345621 ERR21
ENDBATCH
      MSG
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comcetera-0.2.0 spec/comcetera_spec.rb