ichverstehe-shout-bot 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/shout-bot.rb +31 -14
  2. metadata +1 -1
@@ -81,6 +81,13 @@ if $0 == __FILE__ || $0 == "-e"
81
81
  require "context"
82
82
  require "rr"
83
83
 
84
+ class MockSocket
85
+ attr_accessor :in, :out
86
+ def gets() @in.gets end
87
+ def puts(m) @out.puts(m) end
88
+ def eof?() true end
89
+ end
90
+
84
91
  class ShoutBot
85
92
  include Test::Unit::Assertions
86
93
  end
@@ -89,7 +96,10 @@ if $0 == __FILE__ || $0 == "-e"
89
96
  include RR::Adapters::TestUnit
90
97
 
91
98
  def setup
92
- @socket = StringIO.new
99
+ @socket, @server = MockSocket.new, MockSocket.new
100
+ @socket.in, @server.out = IO.pipe
101
+ @server.in, @socket.out = IO.pipe
102
+
93
103
  stub(TCPSocket).open(anything, anything) {@socket}
94
104
  end
95
105
  end
@@ -101,8 +111,7 @@ if $0 == __FILE__ || $0 == "-e"
101
111
 
102
112
  def create_shoutbot_and_register(&block)
103
113
  create_shoutbot &block
104
- @socket.rewind
105
- 2.times { @socket.gets }
114
+ 2.times { @server.gets } # NICK + USER
106
115
  end
107
116
 
108
117
  test "raises error if no block given" do
@@ -113,23 +122,27 @@ if $0 == __FILE__ || $0 == "-e"
113
122
 
114
123
  test "registers to the irc server" do
115
124
  create_shoutbot
116
- @socket.rewind
117
- assert_equal "NICK john\n", @socket.gets
118
- assert_equal "USER john john john :john\n", @socket.gets
125
+ assert_equal "NICK john\n", @server.gets
126
+ assert_equal "USER john john john :john\n", @server.gets
119
127
  end
120
128
 
121
129
  test "sends password if specified" do
122
- ShoutBot.new("irc.freenode.net", 6667, "john", "malbec") {}
123
- @socket.rewind
124
- assert_equal "PASSWORD malbec\n", @socket.gets
130
+ # hey, retarded test!
131
+ ShoutBot.new("irc.freenode.net", 6667, "john", "malbec") {@socket}
132
+ assert_equal "PASSWORD malbec\n", @server.gets
125
133
  end
126
134
 
127
135
  test "falls back to port 6667 if not specified" do
128
136
  # talk about retarded test
129
- mock(TCPSocket).open("irc.freenode.net", 6667) {StringIO.new}
137
+ mock(TCPSocket).open("irc.freenode.net", 6667) {@socket}
130
138
  ShoutBot.new("irc.freenode.net", nil, "john") {}
131
139
  end
132
140
 
141
+ test "quits after doing its job" do
142
+ create_shoutbot_and_register {}
143
+ assert_equal "QUIT\n", @server.gets
144
+ end
145
+
133
146
  test "raises error if no block is given to join" do
134
147
  create_shoutbot do |bot|
135
148
  assert_raises(ArgumentError) {bot.join "integrity"}
@@ -140,7 +153,11 @@ if $0 == __FILE__ || $0 == "-e"
140
153
  create_shoutbot_and_register do |bot|
141
154
  bot.join("integrity") {}
142
155
  end
143
- assert_equal "JOIN #integrity\n", @socket.gets
156
+ assert_equal "JOIN #integrity\n", @server.gets
157
+ end
158
+
159
+ test "doesn't do anything until receiving RPL_MYINFO / 004" do
160
+ # pending
144
161
  end
145
162
 
146
163
  test "joins channel and says something" do
@@ -149,8 +166,8 @@ if $0 == __FILE__ || $0 == "-e"
149
166
  c.say "foo bar!"
150
167
  end
151
168
  end
152
- @socket.gets # JOIN
153
- assert_equal "PRIVMSG #integrity :foo bar!\n", @socket.gets
169
+ @server.gets # JOIN
170
+ assert_equal "PRIVMSG #integrity :foo bar!\n", @server.gets
154
171
  end
155
172
 
156
173
  test "sends private message to user" do
@@ -158,7 +175,7 @@ if $0 == __FILE__ || $0 == "-e"
158
175
  bot.channel = "sr"
159
176
  bot.say "Look Ma, new tests!"
160
177
  end
161
- assert_equal "PRIVMSG sr :Look Ma, new tests!\n", @socket.gets
178
+ assert_equal "PRIVMSG sr :Look Ma, new tests!\n", @server.gets
162
179
  end
163
180
  end
164
181
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ichverstehe-shout-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Rozet