Skip to content

Instantly share code, notes, and snippets.

@jwo
Created April 30, 2012 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jwo/2559654 to your computer and use it in GitHub Desktop.
Save jwo/2559654 to your computer and use it in GitHub Desktop.
Sample mailbox delivery code for Ruby Off Rails
class Message
def deliver_to(mailbox)
mailbox.new_mail(self)
end
end
class Mailbox
def initialize
@flag_raised = false
end
def new_mail(mail)
@flag_raised = true
end
def flag_raised?
@flag_raised
end
end
describe Message do
it "should tell the mailbox about itself" do
mailbox = mock
message = Message.new
mailbox.should_receive(:new_mail).with(message)
message.deliver_to(mailbox)
end
end
describe Mailbox do
it "should not be raised by default" do
Mailbox.new.flag_raised?.should eq(false)
end
describe "#new_mail" do
it "should raise the flag" do
mailbox = Mailbox.new
mailbox.new_mail(stub)
mailbox.flag_raised?.should be_true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment