I'm trying to integrate my application with the Sendgrid api. For example, when a user registers add the user's email to Sendgrid.
As of now I have the following tests:
context "painter registers" do
let(:new_painter) {FactoryGirl.build(:painter)}
it "#add_email_to_sendgrid is called" do
new_painter.should_receive(:add_email_to_sendgrid)
new_painter.save
end
it "Sendgrid#add_email called and should return true" do
new_painter.email = "nobody-sendgrid@painterprofessions.com"
Sendgrid.should_receive(:add_email).with("nobody-sendgrid@painterprofessions.com").and_return(true)
new_painter.save
end
end
In my Painter model I have the following:
after_create :add_email_to_sendgrid
def add_email_to_sendgrid
Sendgrid.add_email(self.email)
end
lib/sendgrid.rb
module Sendgrid
def self.add_email(email_address)
return false
end
end
Everything is working up until the return value of Sendgrid.add_email.
I can change the add_email methods return value to anything and the test will still pass.
Please advise.