spec/integration/mailgun_spec.rb in mailgun-ruby-1.1.1 vs spec/integration/mailgun_spec.rb in mailgun-ruby-1.1.2

- old
+ new

@@ -1,33 +1,80 @@ require 'spec_helper' require 'mailgun' +require 'mailgun/exceptions/exceptions' vcr_opts = { :cassette_name => "instance" } describe 'Mailgun instantiation', vcr: vcr_opts do it 'instantiates an HttpClient object' do expect {@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)}.not_to raise_error end end +vcr_opts = { :cassette_name => "exceptions" } + +describe 'Client exceptions', vcr: vcr_opts do + before(:all) do + @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL) + @domain = TESTDOMAIN + end + + it 'display useful error information' do + begin + @mg_obj.send_message("not-our-doma.in", { + :from => "sally@not-our-doma.in", + :to => "bob@#{@domain}", + :subject => 'Exception Integration Test', + :text => 'INTEGRATION TESTING' + }) + rescue Mailgun::CommunicationError => err + expect(err.message).to eq('404 Not Found: Domain not found: not-our-doma.in') + else + fail + end + end +end + vcr_opts = { :cassette_name => "send_message" } describe 'The method send_message()', vcr: vcr_opts do before(:all) do @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL) @domain = TESTDOMAIN end - + it 'sends a standard message in test mode.' do result = @mg_obj.send_message(@domain, {:from => "bob@#{@domain}", :to => "sally@#{@domain}", :subject => 'Hash Integration Test', :text => 'INTEGRATION TESTING', 'o:testmode' => true} ) result.to_h! expect(result.body).to include("message") expect(result.body).to include("id") + end + + it 'fakes message send while in *client* test mode' do + @mg_obj.enable_test_mode! + + expect(@mg_obj.test_mode?).to eq(true) + + data = { :from => "joe@#{@domain}", + :to => "bob@#{@domain}", + :subject => "Test", + :text => "Test Data" } + + result = @mg_obj.send_message(@domain, data) + + result.to_h! + + expect(result.body).to include("message") + expect(result.body).to include("id") + + expect(result.code).to eq(200) + expect(result.body['id']).to eq("test-mode-mail@localhost") + expect(result.body['message']).to eq("Queued. Thank you.") end it 'sends a message builder message in test mode.' do mb_obj = Mailgun::MessageBuilder.new() mb_obj.from("sender@#{@domain}", {'first' => 'Sending', 'last' => 'User'})