Skip to content

Instantly share code, notes, and snippets.

@evizitei
Created November 13, 2010 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evizitei/675659 to your computer and use it in GitHub Desktop.
Save evizitei/675659 to your computer and use it in GitHub Desktop.
This is put into your cucumber env.rb file to collect all messages sent through Moonshado in an array that you can check later in your scenario.
module Moonshado
class Sms
cattr_accessor :sent_messages
def deliver_sms
raise MoonshadoSMSException.new("Invalid message") unless is_message_valid?(@message)
data = {:sms => {:device_address => format_number(@number), :message => @message.to_s}}
self.class.sent_messages ||= []
self.class.sent_messages << data
response = RestClient::Response.create('{"stat":"ok","id":"sms_id_mock"}', "", {})
parse(response.to_s)
rescue MoonshadoSMSException => exception
raise exception
end
end
end
When /^the sms message "([^"]*)" is sent to "([^"]*)"$/ do |number, message|
Moonshado::Sms.new(message,number).deliver_sms
end
Then /^there should be an SMS sent to "([^"]*)" saying "([^"]*)"$/ do |number, sms_text|
messages = Moonshado::Sms.sent_messages
messages = Moonshado::Sms.sent_messages.select{|data|
data[:sms][:device_address] == number and data[:sms][:message] == sms_text
}
messages.size.should == 1
messages.each{|msg| Moonshado::Sms.sent_messages.delete(msg)}
end
Then /^there should be no SMS messages sent$/ do
if Moonshado::Sms.sent_messages
Moonshado::Sms.sent_messages.size.should == 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment