Sha256: dd5e8fcc5f77f1971f96c3a00232b60f45539ca0168488b48a514b57130bbddc
Contents?: true
Size: 1.86 KB
Versions: 1
Compression:
Stored size: 1.86 KB
Contents
require 'spec_helper' describe ApiConnection do let(:api_connection) { ApiConnection.new } before(:each) do @connection = Nestful::Connection.new Esendex::API_HOST Nestful::Connection.stub(:new) { @connection } @connection.stub(:get) {} @connection.stub(:post) {} Esendex.configure do |config| config.username = random_string config.password = random_string end end describe "#initialise" do subject { ApiConnection.new } it "should set the username" do subject @connection.user.should eq(Esendex.username) end it "should set the password" do subject @connection.password.should eq(Esendex.password) end it "should set the auth to basic" do subject @connection.auth_type.should eq(:basic) end end describe "#get" do let(:url) { random_string } subject { api_connection.get url } it "should call get with headers" do @connection.should_receive(:get).with(url, api_connection.default_headers) subject end context "when 403 raised" do before(:each) do @connection.stub(:get) { raise Nestful::ForbiddenAccess.new(nil) } end it "raises an ForbiddenError" do expect { subject }.to raise_error(ForbiddenError) end end end describe "#post" do let(:url) { random_string } let(:body) { random_string } subject { api_connection.post url, body } it "should call post with headers" do @connection.should_receive(:post).with(url, body, api_connection.default_headers) subject end context "when 403 raised" do before(:each) do @connection.stub(:post) { raise Nestful::ForbiddenAccess.new(nil) } end it "raises an ForbiddenError" do expect { subject }.to raise_error(ForbiddenError) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
esendex-0.4.0 | spec/api_connection_spec.rb |