1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'spec_helper'
require 'ponder/thaum'
require 'ponder/async_irc'
describe Ponder::AsyncIRC do
before(:each) do
@ponder = Ponder::Thaum.new { |c| c.verbose = false }
end
describe Ponder::AsyncIRC::Whois do
context 'tries to get whois information when' do
it 'there is no such nick' do
expect(@ponder).to receive(:raw).with('WHOIS not_online')
EM.run do
whois = @ponder.whois('not_online', 1.5)
whois.callback do |result|
expect(result).to be_falsey
EM.stop
end
whois.errback do
fail 'Wrong Callback called'
EM.stop
end
EM.next_tick { @ponder.parse(":server 401 Ponder not_online :No such nick\r\n") }
end
end
it 'the user is online' do
expect(@ponder).to receive(:raw).with('WHOIS Ridcully')
EM.run do
whois = @ponder.whois('Ridcully', 1.5)
whois.callback do |result|
expect(result).to be_kind_of(Hash)
expect(result[:nick]).to eql('Ridcully')
expect(result[:username]).to eql('ridc')
expect(result[:host]).to eql('host')
expect(result[:real_name]).to eql('Ridcully the wizard')
expect(result[:server]).to be_kind_of(Hash)
expect(result[:server][:address]).to eql('foo.host.net')
expect(result[:server][:name]).to eql('That host thing')
expect(result[:channels]).to be_kind_of(Hash)
expect(result[:channels]['#foo']).to be_nil
expect(result[:channels]['##bar']).to be_nil
expect(result[:channels]['#baz']).to eql('<')
expect(result[:channels]['#sushi']).to eql('@')
expect(result[:channels]['#ramen']).to eql('+')
expect(result[:registered]).to be_truthy
EM.stop
end
whois.errback do
fail 'Wrong Callback called'
EM.stop
end
EM.next_tick do
@ponder.parse(":server 311 Ponder Ridcully :ridc host * :Ridcully the wizard\r\n")
@ponder.parse(":server 312 Ponder Ridcully foo.host.net :That host thing\r\n")
@ponder.parse(":server 319 Ponder Ridcully :#foo ##bar <#baz @#sushi +#ramen\r\n")
@ponder.parse(":server 330 Ponder Ridcully rid_ :is logged in as\r\n")
@ponder.parse(":server 318 Ponder Ridcully :End of /WHOIS list.\r\n")
end
end
end
end
context 'it tries to get channel information when' do
it 'there is no such channel' do
expect(@ponder).to receive(:raw).with('MODE #no_channel')
EM.run do
channel_info = @ponder.channel_info('#no_channel')
channel_info.callback do |result|
expect(result).to be_falsey
EM.stop
end
channel_info.errback do
fail 'Wrong Callback called'
EM.stop
end
EM.next_tick { @ponder.parse(":server 403 Ponder #no_channel :No such channel\r\n") }
end
end
end
end
describe Ponder::AsyncIRC::Topic do
context 'tries to get a topic' do
it ', adds the Deferrable object to the Set and deletes if afterwards for a success' do
expect(@ponder).to receive(:raw).with('TOPIC #channel')
EM.run do
expect(@ponder.deferrables).to be_empty
topic = @ponder.get_topic('#channel')
expect(@ponder.deferrables).to include(topic)
topic.callback do |result|
expect(@ponder.deferrables).to be_empty
EM.stop
end
topic.errback do
fail 'Wrong Callback called'
EM.stop
end
EM.next_tick { @ponder.parse(":server 331 Ponder #channel :No topic is set.\r\n") }
end
end
it ', adds the Deferrable object to the Set and deletes if afterwards for a failure (timeout)' do
expect(@ponder).to receive(:raw).with('TOPIC #channel')
EM.run do
expect(@ponder.deferrables).to be_empty
topic = @ponder.get_topic('#channel', 1.5)
expect(@ponder.deferrables).to include(topic)
topic.callback do |result|
fail 'Wrong Callback called'
EM.stop
end
topic.errback do
expect(@ponder.deferrables).to be_empty
EM.stop
end
end
end
it 'when there is no topic set' do
expect(@ponder).to receive(:raw).with('TOPIC #channel')
EM.run do
expect(@ponder.deferrables).to be_empty
topic = @ponder.get_topic('#channel', 2)
expect(@ponder.deferrables).to include(topic)
topic.callback do |result|
expect(result).to eql({:raw_numeric => 331, :message => 'No topic is set'})
expect(@ponder.deferrables).to be_empty
EM.stop
end
topic.errback do
fail 'Wrong Callback called'
EM.stop
end
EM.next_tick { @ponder.parse(":server 331 Ponder #channel :No topic is set.\r\n") }
end
end
it 'when there is no such channel' do
expect(@ponder).to receive(:raw).with('TOPIC #no_channel')
EM.run do
topic = @ponder.get_topic('#no_channel')
topic.callback do |result|
expect(result).to eql({:raw_numeric => 403, :message => 'No such channel'})
EM.stop
end
topic.errback do
fail 'Wrong Callback called'
EM.stop
end
EM.next_tick { @ponder.parse(":server 403 Ponder #no_channel :No such channel\r\n") }
end
end
it "you're not on that channel" do
expect(@ponder).to receive(:raw).with('TOPIC #channel')
EM.run do
topic = @ponder.get_topic('#channel')
topic.callback do |result|
expect(result).to eql({:raw_numeric => 442, :message => "You're not on that channel"})
EM.stop
end
topic.errback do
fail 'Wrong Callback called'
EM.stop
end
EM.next_tick { @ponder.parse(":server 442 Ponder #channel :You're not on that channel\r\n") }
end
end
end
end
end
|