public
Created

old file

  • Download Gist
mandril_service_spec_new.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
require 'spec_helper'
 
describe 'Mandrill service' do
 
 
 
it "should send the confirmation mail" do
 
# step 1 let's fake collaborators in order to be sure that we
# will only exercise our own code
mandrill_api = double("mandrill_api")
mandrill_messages = double("mandrill_messages")
mandrill_api.stub(:messages).and_return(mandrill_messages)
 
#let's use some local variables to have meaning, that will help to read the asserts
recipient_email = "yrekinger@gmail.com"
language = "nl"
shopping_cart = FactoryGirl.build(:shopping_cart, :with_articles, items_count: 5)
# this is our subject, the object which will be tested
subject = MandrillService::TransactionalEmailSender.new(mandrill_api, recipient_email, language)
 
# once the test is finished that call should have been made
# we know that this called should have been made because we know very well the mandrill API
# we should probably add some specification to the shopping cart in order to have better
# expected params and options
expected_template_name = "RspecTestingTemplate.nl"
expected_params = []
expected_options = {}
mandrill_messages.should_receive('send_template').with(expected_template_name, expected_params, expected_options)
 
# this should not be stubbed or mocked because it would replace the method with an empty one
# we have already made a very good assert on the previous line
#mandrill_service.should_receive('send_template_message').with("RspecTestingTemplate.nl", [], {})
 
@ let's call the method we are testing
mandrill_service.send_cart_confirmation shopping_cart
end
end
mandril_service_spec_old.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
require 'spec_helper'
 
describe 'Mandrill service' do
 
it "should send the confirmation mail" do
 
mandrill_api = Mandrill::API.new(KrefelWs::Application.config.mandrill_service.api_key)
mandrill_messages = mandrill_api.messages
 
mandrill_api = double("mandrill_api")
mandrill_messages = double("mandrill_messages")
 
mandrill_api.stub(:messages).and_return(mandrill_messages)
#mandrill_messages.stub(:send_template).and_return(true)
 
mandrill_service = MandrillService::TransactionalEmailSender.new(mandrill_api, "yrekinger@gmail.com", "nl")
 
mandrill_messages.should_receive('send_template').with("RspecTestingTemplate.nl", [], {})
 
mandrill_service.should_receive('send_template_message').with("RspecTestingTemplate.nl", [], {})
 
mandrill_service.send_cart_confirmation nil
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.