spec/mailgun/sender_spec.rb in multi_mail-0.1.0 vs spec/mailgun/sender_spec.rb in multi_mail-0.1.1

- old
+ new

@@ -1,7 +1,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -require 'multi_mail/mailgun/sender' describe MultiMail::Sender::Mailgun do let :message do Mail.new do date Time.at(946702800) @@ -50,42 +49,45 @@ describe '#initialize' do it 'should raise an error if :api_key is missing' do expect{ message.delivery_method MultiMail::Sender::Mailgun, :domain => 'xxx' - message.deliver # request not sent }.to raise_error(ArgumentError, "Missing required arguments: api_key") end it 'should raise an error if :domain is missing' do expect{ message.delivery_method MultiMail::Sender::Mailgun, :api_key => 'xxx' - message.deliver # request not sent }.to raise_error(ArgumentError, "Missing required arguments: domain") end it 'should raise an error if :api_key is nil' do expect{ message.delivery_method MultiMail::Sender::Mailgun, :api_key => nil, :domain => 'xxx' - message.deliver # request not sent }.to raise_error(ArgumentError, "Missing required arguments: api_key") end it 'should raise an error if :domain is nil' do expect{ message.delivery_method MultiMail::Sender::Mailgun, :api_key => 'xxx', :domain => nil - message.deliver # request not sent }.to raise_error(ArgumentError, "Missing required arguments: domain") end - it 'should raise an error if :domain or :api_key are invalid' do + it 'should raise an error if :api_key is invalid' do expect{ - message.delivery_method MultiMail::Sender::Mailgun, :api_key => 'xxx', :domain => 'xxx' + message.delivery_method MultiMail::Sender::Mailgun, :api_key => 'xxx', :domain => 'multimail.mailgun.org' message.deliver }.to raise_error(MultiMail::InvalidAPIKey) end + it 'should raise an error if :domain is invalid' do + expect{ + message.delivery_method MultiMail::Sender::Mailgun, :api_key => ENV['MAILGUN_API_KEY'], :domain => 'xxx' + message.deliver + }.to raise_error(MultiMail::InvalidRequest, "Domain not found: xxx") + end + it 'should assign custom settings' do sender = MultiMail::Sender::Mailgun.new(:api_key => 'xxx', :domain => 'xxx') sender.api_key.should == 'xxx' sender.domain.should == 'xxx' @@ -164,9 +166,13 @@ expect{message_without_from.deliver!}.to raise_error(MultiMail::MissingSender, "'from' parameter is missing") end it 'should not send a message without a To header' do expect{message_without_to.deliver!}.to raise_error(MultiMail::MissingRecipients, "'to' parameter is missing") + end + + it 'should send a message without a subject' do + expect{message_without_subject.deliver!}.to_not raise_error end it 'should not send a message without a body' do expect{message_without_body.deliver!}.to raise_error(MultiMail::MissingBody, "Need at least one of 'text' or 'html' parameters specified") end