require 'spec_helper' describe 'posting a delivery', :integration do let(:contact_email) { "test@example.com" } let(:email_name) { :test } let(:data) { { :greeting => "Gday!" } } before do Mailstro.configure do |config| config.api_key = 'lolapi' end end let(:expected_body) {{ "api_key" => "lolapi", "to" => "test@example.com", "email_name" => "test", "data" => { "greeting" => "Gday!" } }} it "succesfully submits a delivery to mailstro" do stub_request(:post, "https://api.mailstroapp.com/v1/deliveries"). with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json")) response = Mailstro.deliver(email_name, :to => contact_email, :data => data ) response['success'].should == true end it "raises an error if the api key is not authorized" do stub_request(:post, "https://api.mailstroapp.com/v1/deliveries"). to_return(:status => 401) expect do Mailstro.deliver(email_name, :to => contact_email, :data => data ) end.to raise_error(Mailstro::Error::AuthorisationError, "api_key not authorised") end end