spec/api_connection_spec.rb in esendex-0.4.0 vs spec/api_connection_spec.rb in esendex-0.5.0

- old
+ new

@@ -1,79 +1,79 @@ -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 +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 \ No newline at end of file