Permalink
Browse files

More refactorings.

  * Removed the connect event. It will be handled inside the loop.
  * Refactored specs: now they test only one thing per spec.
  • Loading branch information...
david committed Jun 3, 2008
1 parent ba5c025 commit 421e2df7551c0ab53db20e55d26a254f2090bdae
Showing with 14 additions and 9 deletions.
  1. +0 −1 lib/minibot/daemon.rb
  2. +14 −8 spec/daemon_spec.rb
View
@@ -11,7 +11,6 @@ def run
begin
connect(@options[:server], @options[:port])
authenticate(@options[:nick], @options[:username], @options[:realname])
- handle_event :connect
main_loop
ensure
close
View
@@ -10,18 +10,24 @@ def daemon(options = {})
)
end
- it "should connect to a server" do
- socket = mock("socket")
- socket.should_receive(:print).with("NICK nick\r\n").ordered
- socket.should_receive(:print).with("USER spec xxx xxx :Spec User\r\n").ordered
-
+ it "should connect" do
+ socket = mock("socket", :null_object => true)
TCPSocket.should_receive(:new).with('irc.freenode.net', 6667).and_return(socket)
d = daemon
- d.should_receive(:main_loop)
- d.should_receive(:close)
+ d.send(:connect, 'irc.freenode.net', 6667)
+ puts d.inspect
+ d.instance_variable_get("@socket").should == socket
+ end
- d.run
+ it "should authenticate" do
+ socket = mock("socket", :null_object => true)
+ socket.should_receive(:print).with("NICK nick\r\n").ordered
+ socket.should_receive(:print).with("USER spec xxx xxx :Spec User\r\n").ordered
+
+ d = daemon
+ d.instance_variable_set("@socket", socket)
+ d.send(:authenticate, 'nick', 'spec', 'Spec User')
end
describe "#dispatch" do

0 comments on commit 421e2df

Please sign in to comment.