flamethrower 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,7 +57,7 @@ module Flamethrower
57
57
 
58
58
  def handle_topic(message)
59
59
  find_channel_or_error(message.parameters.first) do |channel|
60
- channel.to_campfire.send_topic!(message.parameters.last) if message.parameters.size > 1
60
+ channel.to_campfire.send_topic(message.parameters.last) if message.parameters.size > 1
61
61
  server.send_topic(channel)
62
62
  end
63
63
  end
@@ -80,22 +80,26 @@ module Flamethrower
80
80
  room = channel.to_campfire
81
81
  channel.users << server.current_user
82
82
  room.join
83
- room.fetch_room_info
84
- room.start_thread
85
- server.send_topic(channel)
86
- server.send_userlist(channel)
83
+ room.start
84
+ end
85
+ end
86
+
87
+ def handle_who(message)
88
+ find_channel_or_error(message.parameters.first) do |channel|
89
+ server.send_who(channel)
87
90
  end
88
91
  end
89
92
 
90
93
  def handle_part(message)
91
94
  find_channel_or_error(message.parameters.first) do |channel|
92
95
  room = channel.to_campfire
93
- room.kill_thread!
96
+ room.stop
97
+ server.send_part(server.current_user, channel)
94
98
  end
95
99
  end
96
100
 
97
101
  def handle_quit(message)
98
- server.irc_channels.each {|c| c.to_campfire.kill_thread!}
102
+ server.irc_channels.each {|c| c.to_campfire.stop}
99
103
  end
100
104
  end
101
105
  end
@@ -5,6 +5,8 @@ module Flamethrower
5
5
  RPL_MOTD = 372
6
6
  RPL_ENDOFMOTD = 376
7
7
  RPL_TOPIC = 332
8
+ RPL_WHOREPLY = 352
9
+ RPL_ENDOFWHO = 315
8
10
  RPL_NAMEREPLY = 353
9
11
  RPL_ENDOFNAMES = 366
10
12
  RPL_CHANNELMODEIS = 324
@@ -33,6 +33,19 @@ module Flamethrower
33
33
  end
34
34
  end
35
35
 
36
+ def send_rename(from, to)
37
+ send_message ":#{from} NICK #{to}"
38
+ end
39
+
40
+ def send_who(channel)
41
+ send_messages do |messages|
42
+ channel.users.each do |user|
43
+ messages << reply(RPL_WHOREPLY, "#{channel.name} #{user.nickname} #{user.hostname} localhost #{user.nickname} H :0 #{user.nickname}")
44
+ end
45
+ messages << reply(RPL_ENDOFWHO, "#{channel.name} :/End of /WHO list")
46
+ end
47
+ end
48
+
36
49
  def send_channel_mode(channel)
37
50
  send_message reply(RPL_CHANNELMODEIS, "#{channel.name} #{channel.mode}")
38
51
  end
@@ -45,6 +58,10 @@ module Flamethrower
45
58
  send_message reply(RPL_UMODEIS, @current_user.mode)
46
59
  end
47
60
 
61
+ def send_part(user, channel)
62
+ send_message ":#{user.to_s} PART #{channel.name}"
63
+ end
64
+
48
65
  def reply(code, message)
49
66
  ":#{@current_user.hostname} #{code} #{@current_user.nickname} #{message}"
50
67
  end
@@ -13,7 +13,7 @@ module Flamethrower
13
13
  def after_connect
14
14
  send_motd
15
15
  populate_irc_channels
16
- send_channel_list
16
+ populate_my_user
17
17
  end
18
18
 
19
19
  def send_message(msg)
@@ -36,7 +36,11 @@ module Flamethrower
36
36
  end
37
37
 
38
38
  def populate_irc_channels
39
- @irc_channels = campfire_connection.rooms.map(&:to_irc)
39
+ campfire_connection.fetch_rooms
40
+ end
41
+
42
+ def populate_my_user
43
+ campfire_connection.fetch_my_user
40
44
  end
41
45
 
42
46
  end
@@ -7,6 +7,18 @@ module Flamethrower
7
7
  def unbind
8
8
  @server.connections.delete(self)
9
9
  end
10
+
11
+ def stop
12
+ irc_channels.map do |channel|
13
+ channel.to_campfire.stop
14
+ end
15
+ end
16
+
17
+ def streams_alive?
18
+ irc_channels.any? do |channel|
19
+ channel.to_campfire.alive?
20
+ end
21
+ end
10
22
  end
11
23
 
12
24
  class EventServer
@@ -34,34 +46,33 @@ module Flamethrower
34
46
  def stop
35
47
  FLAMETHROWER_LOGGER.info("Killing room threads")
36
48
  @connections.each do |connection|
37
- connection.irc_channels.map do |channel|
38
- channel.to_campfire.kill_thread!
39
- end
49
+ connection.stop
50
+ connection.close_connection
40
51
  end
41
52
  EventMachine.stop_server(@signature)
42
- die_safely
53
+ EventMachine.add_periodic_timer(0.2) { die_safely }
43
54
  end
44
55
 
56
+ private
57
+
45
58
  def die_safely
46
59
  FLAMETHROWER_LOGGER.info("Waiting for streams and connections to die")
47
- if streams_alive? && connections_alive?
48
- EventMachine.add_periodic_timer(1) { die_safely }
60
+ if any_streams_alive? || any_connections_alive?
61
+ return
49
62
  else
50
63
  FLAMETHROWER_LOGGER.info("Done.")
51
64
  EventMachine.stop
52
65
  end
53
66
  end
54
67
 
55
- def streams_alive?
68
+ def any_streams_alive?
56
69
  @connections.any? do |connection|
57
- connection.irc_channels.any? do |channel|
58
- channel.to_campfire.alive?
59
- end
70
+ connection.streams_alive?
60
71
  end
61
72
  end
62
73
 
63
- def connections_alive?
64
- @connections.size <= 0
74
+ def any_connections_alive?
75
+ @connections.size > 0
65
76
  end
66
77
  end
67
78
  end
@@ -1 +1 @@
1
- {"room_id":73541,"created_at":"2010/12/14 20:48:30 +0000","body":"Line one\\n\\tpoint one\\n\\tpoint two\\npoint three","id":289383470,"user_id":703609,"type":"PasteMessage"}
1
+ {"room_id":73541,"created_at":"2010/12/14 20:48:30 +0000","body":"Line one\n\tpoint one\n\tpoint two\npoint three","id":289383470,"user_id":703609,"type":"PasteMessage"}
data/spec/spec_helper.rb CHANGED
@@ -2,11 +2,12 @@ $:.unshift File.join(File.dirname(__FILE__), "../lib")
2
2
 
3
3
  require 'flamethrower'
4
4
  require 'server/mock_server'
5
+ require 'webmock/rspec'
5
6
  require 'json'
6
- require 'fakeweb'
7
7
  require 'time'
8
8
 
9
- ::FLAMETHROWER_LOGGER = Logger.new("/dev/null") unless Object.const_defined?("FLAMETHROWER_LOGGER")
9
+ #::FLAMETHROWER_LOGGER = Logger.new("/dev/null") unless Object.const_defined?("FLAMETHROWER_LOGGER")
10
+ ::FLAMETHROWER_LOGGER = Logger.new("/Users/blake/test.log") unless Object.const_defined?("FLAMETHROWER_LOGGER")
10
11
 
11
12
  def json_fixture(name)
12
13
  file = File.join(File.dirname(__FILE__), "fixtures/#{name}.json")
@@ -4,30 +4,56 @@ describe Flamethrower::Campfire::Connection do
4
4
  before do
5
5
  @server = Flamethrower::MockServer.new
6
6
  @connection = @server.campfire_connection
7
- FakeWeb.allow_net_connect = false
7
+ end
8
+
9
+ describe "#fetch_my_user" do
10
+ it "retrieves my user and stores it on the connection" do
11
+ stub_request(:get, "https://mydomain.campfirenow.com/users/me.json").
12
+ with(:headers => {'Authorization'=>['mytoken', 'x']}).
13
+ to_return(:status => 200, :body => json_fixture("user"))
14
+ EM.run_block { @connection.fetch_my_user }
15
+ @server.current_user.nickname.should == "blake"
16
+ end
17
+
18
+ it "renames your current user to the new current user" do
19
+ @server.current_user = Flamethrower::Irc::User.new(:nickname => "bob")
20
+ stub_request(:get, "https://mydomain.campfirenow.com/users/me.json").
21
+ with(:headers => {'Authorization'=>['mytoken', 'x']}).
22
+ to_return(:status => 200, :body => json_fixture("user"))
23
+ @server.should_receive(:send_message).with(":bob NICK blake")
24
+ EM.run_block { @connection.fetch_my_user }
25
+ end
8
26
  end
9
27
 
10
28
  describe "#rooms" do
11
29
  it "retrieves a list of rooms from JSON" do
12
- FakeWeb.register_uri(:get, "https://mytoken:x@mydomain.campfirenow.com/rooms.json", :body => json_fixture("rooms"), :status => ["200", "OK"])
13
- room = @connection.rooms.first
30
+ stub_request(:get, "https://mydomain.campfirenow.com/rooms.json").
31
+ with(:headers => {'Authorization'=>['mytoken', 'x']}).
32
+ to_return(:status => 200, :body => json_fixture("rooms"))
33
+ EM.run_block { @connection.fetch_rooms }
34
+ room = @server.irc_channels.first.to_campfire
14
35
  room.number.should == 347348
15
36
  room.name.should == "Room 1"
16
37
  room.topic.should == "some topic"
17
38
  end
18
39
 
19
40
  it "makes the http request with a token in basic auth" do
20
- FakeWeb.register_uri(:get, "https://mytoken:x@mydomain.campfirenow.com/rooms.json", :body => json_fixture("rooms"), :status => ["200", "OK"])
21
- @connection.rooms
22
- FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64("#{@connection.token}:x").chomp}"
41
+ stub_request(:get, "https://mydomain.campfirenow.com/rooms.json").
42
+ with(:headers => {'Authorization'=>['mytoken', 'x']}).
43
+ to_return(:status => 200, :body => json_fixture("rooms"))
44
+ EM.run_block { @connection.fetch_rooms }
45
+ assert_requested(:get, "https://mydomain.campfirenow.com/rooms.json") {|req| req.headers['Authorization'].should == ["mytoken", "x"]}
23
46
  end
24
47
 
25
48
  it "returns empty set if not a successful response" do
26
- FakeWeb.register_uri(:get, "https://mytoken:x@mydomain.campfirenow.com/rooms.json", :status => ["400", "Bad Request"])
27
- @connection.rooms.should == []
49
+ stub_request(:get, "https://mydomain.campfirenow.com/rooms.json").
50
+ with(:headers => {'Authorization'=>['mytoken', 'x']}).
51
+ to_return(:status => 400)
52
+ EM.run_block { @connection.fetch_rooms }
53
+ @server.irc_channels.should == []
28
54
  end
29
55
 
30
- it "sends a motd error message if unable to fetch room list" do
56
+ xit "sends a motd error message if unable to fetch room list" do
31
57
  @connection.should_receive(:campfire_get).and_raise(SocketError)
32
58
  @server.should_receive(:send_message).with(@server.reply(Flamethrower::Irc::Codes::RPL_MOTD, ":ERROR: Unable to fetch room list! Check your connection?"))
33
59
  @connection.rooms.should == []
@@ -67,7 +67,11 @@ describe Flamethrower::Campfire::Message do
67
67
  message = Flamethrower::Campfire::Message.new(json)
68
68
  message.user = @campfire_user
69
69
  message.room = @room
70
- message.to_irc.to_s.should == ":#{@irc_user.to_s} PRIVMSG #{@channel.name} :Line one\\n\\tpoint one\\n\\tpoint two\\npoint three"
70
+ expected = ":#{@irc_user.to_s} PRIVMSG #{@channel.name} :Line one\r\n"
71
+ expected << ":#{@irc_user.to_s} PRIVMSG #{@channel.name} :\tpoint one\r\n"
72
+ expected << ":#{@irc_user.to_s} PRIVMSG #{@channel.name} :\tpoint two\r\n"
73
+ expected << ":#{@irc_user.to_s} PRIVMSG #{@channel.name} :point three"
74
+ message.to_irc.to_s.should == expected
71
75
  end
72
76
  end
73
77
 
@@ -2,7 +2,9 @@ require File.join(File.dirname(__FILE__), "../../spec_helper")
2
2
 
3
3
  describe Flamethrower::Campfire::Room do
4
4
  before do
5
+ @server = Flamethrower::MockServer.new
5
6
  @room = Flamethrower::Campfire::Room.new("mydomain", "mytoken", "id" => 347348, "topic" => "some topic", "name" => "some name")
7
+ @room.server = @server
6
8
  @user = Flamethrower::Campfire::User.new('name' => "bob", 'id' => 489198)
7
9
  @user2 = Flamethrower::Campfire::User.new('name' => "bill", 'id' => 123456)
8
10
  end
@@ -30,64 +32,82 @@ describe Flamethrower::Campfire::Room do
30
32
 
31
33
  describe "#send_topic!" do
32
34
  it "sets the topic when the campfire API returns 200" do
33
- FakeWeb.register_uri(:put, "https://mytoken:x@mydomain.campfirenow.com/room/347348.json", :body => json_fixture("room_update"), :status => ["200", "OK"])
34
- @room.send_topic!("some updated topic")
35
+ stub_request(:put, "https://mydomain.campfirenow.com/room/347348.json").
36
+ with(:headers => {'Authorization'=>['mytoken', 'x'], 'Content-Type'=>'application/json'}).
37
+ to_return(:status => 200, :body => json_fixture("room_update"))
38
+ EM.run_block { @room.send_topic("some updated topic") }
35
39
  @room.topic.should == "some updated topic"
36
40
  end
37
41
 
38
42
  it "keeps the previous topic when the campfire API returns non 200" do
39
- FakeWeb.register_uri(:put, "https://mytoken:x@mydomain.campfirenow.com/room/347348.json", :body => json_fixture("room_update"), :status => ["400", "Bad Request"])
43
+ stub_request(:put, "https://mydomain.campfirenow.com/room/347348.json").
44
+ with(:headers => {'Authorization'=>['mytoken', 'x'], 'Content-Type'=>'application/json'}).
45
+ to_return(:status => 400, :body => json_fixture("room_update"))
40
46
  @room.instance_variable_set("@topic", "some old topic")
41
- @room.send_topic!("some updated topic")
47
+ EM.run_block { @room.send_topic("some updated topic") }
42
48
  @room.topic.should == "some old topic"
43
49
  end
44
50
  end
45
51
 
46
52
  describe "#fetch_room_info" do
47
53
  before do
48
- FakeWeb.register_uri(:get, "https://mytoken:x@mydomain.campfirenow.com/room/347348.json", :body => json_fixture("room"), :status => ["200", "OK"])
54
+ stub_request(:get, "https://mydomain.campfirenow.com/room/347348.json").
55
+ with(:headers => {'Authorization'=>['mytoken', 'x']}).
56
+ to_return(:status => 200, :body => json_fixture("room"))
49
57
  end
50
58
 
51
59
  it "retrieves a list of users and stores them as user objects" do
52
- @room.fetch_room_info
60
+ EM.run_block { @room.fetch_room_info }
53
61
  @room.users.all? {|u| u.is_a?(Flamethrower::Campfire::User)}.should be_true
54
62
  end
55
63
 
64
+ it "doesn't send the room join info if the room has already been joined" do
65
+ @room.instance_variable_set("@room_info_sent", true)
66
+ @room.should_not_receive(:send_info)
67
+ EM.run_block { @room.fetch_room_info }
68
+ end
69
+
56
70
  it "makes the http request with a token in basic auth" do
57
- @room.fetch_room_info
58
- FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64("#{@room.token}:x").chomp}"
71
+ EM.run_block { @room.fetch_room_info }
72
+ assert_requested(:get, "https://mydomain.campfirenow.com/room/347348.json") {|req| req.headers['Authorization'].should == ["mytoken", "x"]}
59
73
  end
60
74
  end
61
75
 
62
76
  describe "#fetch_users" do
63
77
  it "makes a call to the campfire api to fetch user information" do
64
- FakeWeb.register_uri(:get, "https://mytoken:x@mydomain.campfirenow.com/users/734581.json", :body => json_fixture("user"), :status => ["200", "OK"])
78
+ stub_request(:get, "https://mydomain.campfirenow.com/users/734581.json").
79
+ with(:headers => {'Authorization'=>['mytoken', 'x']}).
80
+ to_return(:status => 200, :body => json_fixture("user"))
65
81
  @room.instance_variable_get("@users_to_fetch") << Flamethrower::Campfire::Message.new(JSON.parse(json_fixture("enter_message")))
66
- @room.fetch_users
82
+ EM.run_block { @room.fetch_users }
67
83
  @room.users.map(&:name).should == ["blake"]
68
84
  end
69
85
 
70
86
  it "fetches using the 'user_id' field if a streaming message" do
71
- FakeWeb.register_uri(:get, "https://mytoken:x@mydomain.campfirenow.com/users/734581.json", :body => json_fixture("user"), :status => ["200", "OK"])
87
+ stub_request(:get, "https://mytoken:x@mydomain.campfirenow.com/users/734581.json").to_return(:body => json_fixture("user"), :status => 200)
72
88
  @room.instance_variable_get("@users_to_fetch") << Flamethrower::Campfire::Message.new(JSON.parse(json_fixture("enter_message")))
73
- @room.should_receive(:campfire_get).with("/users/734581.json")
74
- @room.fetch_users
89
+ @room.should_receive(:campfire_get).with("/users/734581.json").and_return(mock(:post, :callback => nil))
90
+ EM.run_block { @room.fetch_users }
75
91
  end
76
92
 
77
93
  context "successfully get user info" do
78
94
  it "enqueues an EnterMessage into @inbound_messages for displaying in irc" do
79
- FakeWeb.register_uri(:get, "https://mytoken:x@mydomain.campfirenow.com/users/734581.json", :body => json_fixture("user"), :status => ["200", "OK"])
95
+ stub_request(:get, "https://mydomain.campfirenow.com/users/734581.json").
96
+ with(:headers => {'Authorization'=>['mytoken', 'x']}).
97
+ to_return(:status => 200, :body => json_fixture("user"))
80
98
  @room.instance_variable_get("@users_to_fetch") << Flamethrower::Campfire::Message.new(JSON.parse(json_fixture("enter_message")))
81
- @room.fetch_users
99
+ EM.run_block { @room.fetch_users }
82
100
  message = @room.inbound_messages.pop.user.number.should == 734581
83
101
  end
84
102
  end
85
103
 
86
104
  context "fails to get user info" do
87
105
  it "doesn't enqueue an EnterMessage" do
88
- FakeWeb.register_uri(:get, "https://mytoken:x@mydomain.campfirenow.com/users/734581.json", :status => ["400", "Bad Request"])
106
+ stub_request(:get, "https://mydomain.campfirenow.com/users/734581.json").
107
+ with(:headers => {'Authorization'=>['mytoken', 'x']}).
108
+ to_return(:status => 400, :body => json_fixture("user"))
89
109
  @room.instance_variable_get("@users_to_fetch") << Flamethrower::Campfire::Message.new(JSON.parse(json_fixture("enter_message")))
90
- @room.fetch_users
110
+ EM.run_block { @room.fetch_users }
91
111
  message = @room.inbound_messages.size.should == 0
92
112
  end
93
113
  end
@@ -95,13 +115,19 @@ describe Flamethrower::Campfire::Room do
95
115
 
96
116
  describe "#join" do
97
117
  it "returns true when posting to the room join call succeeds" do
98
- FakeWeb.register_uri(:post, "https://mytoken:x@mydomain.campfirenow.com/room/347348/join.json", :status => ["200", "OK"])
99
- @room.join.should == true
118
+ stub_request(:post, "https://mydomain.campfirenow.com/room/347348/join.json").
119
+ with(:headers => {'Authorization'=>['mytoken', 'x'], 'Content-Type'=>'application/json'}).
120
+ to_return(:status => 200)
121
+ EM.run_block { @room.join }
122
+ @room.joined.should be_true
100
123
  end
101
124
 
102
125
  it "returns false when posting to the room join call fails" do
103
- FakeWeb.register_uri(:post, "https://mytoken:x@mydomain.campfirenow.com/room/347348/join.json", :status => ["400", "Bad Request"])
104
- @room.join.should == false
126
+ stub_request(:post, "https://mydomain.campfirenow.com/room/347348/join.json").
127
+ with(:headers => {'Authorization'=>['mytoken', 'x'], 'Content-Type'=>'application/json'}).
128
+ to_return(:status => 400)
129
+ EM.run_block { @room.join }
130
+ @room.joined.should be_false
105
131
  end
106
132
  end
107
133
 
@@ -199,59 +225,56 @@ describe Flamethrower::Campfire::Room do
199
225
 
200
226
  describe "#post_messages" do
201
227
  it "pops the message off the queue and posts it to the campfire api" do
202
- FakeWeb.register_uri(:post, "https://mytoken:x@mydomain.campfirenow.com/room/347348/speak.json", :body => json_fixture("speak_message"), :status => ["201", "Created"])
228
+ stub_request(:post, "https://mydomain.campfirenow.com/room/347348/speak.json").
229
+ with(:headers => {'Authorization'=>['mytoken', 'x'], 'Content-Type'=>'application/json'}).
230
+ to_return(:status => 200, :body => json_fixture("speak_message"))
203
231
  message = Flamethrower::Campfire::Message.new('type' => 'TextMessage', 'body' => 'Hello there', 'user' => @user, 'room' => @room)
204
232
  @room.outbound_messages << message
205
- @room.post_messages
233
+ EM.run_block { @room.post_messages }
206
234
  @room.outbound_messages.size.should == 0
207
235
  end
208
236
 
209
237
  it "adds the message to the failed_messages array if it fails to post to the campfire API" do
210
- FakeWeb.register_uri(:post, "https://mytoken:x@mydomain.campfirenow.com/room/347348/speak.json", :status => ["400", "Bad Request"])
238
+ stub_request(:post, "https://mydomain.campfirenow.com/room/347348/speak.json").
239
+ with(:headers => {'Authorization'=>['mytoken', 'x'], 'Content-Type'=>'application/json'}).
240
+ to_return(:status => 400, :body => json_fixture("speak_message"))
241
+
211
242
  message = Flamethrower::Campfire::Message.new('type' => 'TextMessage', 'body' => 'Hello there', 'user' => @user, 'room' => @room)
212
243
  @room.outbound_messages << message
213
- @room.post_messages
244
+ EM.run_block { @room.post_messages }
214
245
  @room.outbound_messages.size.should == 0
215
246
  @room.failed_messages.size.should == 1
216
247
  end
217
248
 
218
249
  it "marks the message as failed when not able to deliver" do
219
- FakeWeb.register_uri(:post, "https://mytoken:x@mydomain.campfirenow.com/room/347348/speak.json", :status => ["400", "Bad Request"])
250
+ stub_request(:post, "https://mydomain.campfirenow.com/room/347348/speak.json").
251
+ with(:headers => {'Authorization'=>['mytoken', 'x'], 'Content-Type'=>'application/json'}).
252
+ to_return(:status => 400, :body => json_fixture("speak_message"))
253
+
220
254
  message = Flamethrower::Campfire::Message.new('type' => 'TextMessage', 'body' => 'Hello there', 'user' => @user, 'room' => @room)
221
255
  @room.outbound_messages << message
222
- @room.post_messages
256
+ EM.run_block { @room.post_messages }
223
257
  message.status.should == "failed"
224
258
  end
225
259
 
226
260
  it "marks the message as delivered if successfully posted to campfire" do
227
- FakeWeb.register_uri(:post, "https://mytoken:x@mydomain.campfirenow.com/room/347348/speak.json", :body => json_fixture("speak_message"), :status => ["201", "Created"])
261
+ stub_request(:post, "https://mydomain.campfirenow.com/room/347348/speak.json").
262
+ with(:headers => {'Authorization'=>['mytoken', 'x'], 'Content-Type'=>'application/json'}).
263
+ to_return(:status => 201, :body => json_fixture("speak_message"))
264
+
228
265
  message = Flamethrower::Campfire::Message.new('type' => 'TextMessage', 'body' => 'Hello there', 'user' => @user, 'room' => @room)
229
266
  @room.outbound_messages << message
230
- @room.post_messages
267
+ EM.run_block { @room.post_messages }
231
268
  message.status.should == "delivered"
232
269
  end
233
270
 
234
271
  it "sends the right json" do
235
- FakeWeb.register_uri(:post, "https://mytoken:x@mydomain.campfirenow.com/room/347348/speak.json", :body => json_fixture("speak_message"), :status => ["201", "Created"])
272
+ stub_request(:post, "https://mytoken:x@mydomain.campfirenow.com/room/347348/speak.json").to_return(:body => json_fixture("speak_message"), :status => 201)
236
273
  message = Flamethrower::Campfire::Message.new('type' => 'TextMessage', 'body' => 'Hello there', 'user' => @user, 'room' => @room)
237
274
  @room.outbound_messages << message
238
275
  expected_json = {"message"=>{"body"=>"Hello there", "type"=>"TextMessage"}}.to_json
239
- @room.should_receive(:campfire_post).with("/room/#{@room.number}/speak.json", expected_json)
240
- @room.post_messages
241
- end
242
- end
243
-
244
- describe "#retrieve_messages" do
245
- it "returns all the messages in the message buffer" do
246
- @room.inbound_messages << "one"
247
- @room.inbound_messages << "two"
248
- @room.retrieve_messages.should == ["one", "two"]
249
- end
250
-
251
- it "pops the messages from the messages array" do
252
- @room.inbound_messages << "one"
253
- @room.retrieve_messages.should == ["one"]
254
- @room.inbound_messages.size.should == 0
276
+ @room.should_receive(:campfire_post).with("/room/#{@room.number}/speak.json", expected_json).and_return(mock(:post, :callback => nil))
277
+ EM.run_block { @room.post_messages }
255
278
  end
256
279
  end
257
280