Permalink
Browse files

Fail all listeners when invalid data is received.

  • Loading branch information...
1 parent 3a97981 commit 7b68769f40332f87b4938628cade97114e26969a @ConradIrwin ConradIrwin committed Jul 2, 2011
Showing with 9 additions and 0 deletions.
  1. +5 −0 lib/em-imap/response_parser.rb
  2. +4 −0 spec/response_parser_spec.rb
View
5 lib/em-imap/response_parser.rb
@@ -39,10 +39,15 @@ def receive_data(data)
# Callback used by receive data.
def receive_response(response); end
+ # Callback used if something goes wrong.
+ def fail_all(error); end
+
private
def parse(line)
@parser.parse(line)
+ rescue Net::IMAP::ResponseParseError => e
+ fail_all e
end
end
end
View
4 spec/response_parser_spec.rb
@@ -47,4 +47,8 @@
@response_parser.receive_data "ogs\r\n"
end
+ it "should fail the connection when invalid data is received" do
+ @response_parser.should_receive(:fail_all).with(an_instance_of(Net::IMAP::ResponseParseError))
+ @response_parser.receive_data "lol ??\r\n"
+ end
end

0 comments on commit 7b68769

Please sign in to comment.