Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
rename #puts so you can puts while you puts
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed May 2, 2012
1 parent 20dbca5 commit f910c50
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
31 changes: 16 additions & 15 deletions services/irc.rb
Expand Up @@ -37,34 +37,35 @@ def send_messages(messages)
botname = data['nick'].to_s.empty? ? "GitHub#{rand(200)}" : data['nick']
command = data['notice'].to_i == 1 ? 'NOTICE' : 'PRIVMSG'

self.puts "PASS #{data['password']}" if !data['password'].to_s.empty?
self.puts "NICK #{botname}"
self.puts "MSG NICKSERV IDENTIFY #{data['nickservidentify']}" if !data['nickservidentify'].to_s.empty?
self.puts "USER #{botname} 8 * :GitHub IRCBot"
irc_puts "PASS #{data['password']}" if !data['password'].to_s.empty?
irc_puts "NICK #{botname}"
irc_puts "MSG NICKSERV IDENTIFY #{data['nickservidentify']}" if !data['nickservidentify'].to_s.empty?
irc_puts "USER #{botname} 8 * :GitHub IRCBot"

loop do
case self.gets
case irc_gets
when / 00[1-4] #{Regexp.escape(botname)} /
break
when /^PING\s*:\s*(.*)$/
self.puts "PONG #{$1}"
irc_puts "PONG #{$1}"
end
end

without_join = data['message_without_join'] == '1'
rooms.each do |room|
room, pass = room.split("::")
self.puts "JOIN #{room} #{pass}" unless without_join
irc_puts "JOIN #{room} #{pass}" unless without_join

Array(messages).each do |message|
self.puts "#{command} #{room} :#{message}"
irc_puts "#{command} #{room} :#{message}"
end

self.puts "PART #{room}" unless without_join
irc_puts "PART #{room}" unless without_join
end

self.puts "QUIT"
self.gets until self.eof?
irc_puts "QUIT"
irc_response = []
irc_response << irc_gets unless irc_eof?
rescue SocketError => boom
if boom.to_s =~ /getaddrinfo: Name or service not known/
raise_config_error 'Invalid host'
Expand All @@ -79,15 +80,15 @@ def send_messages(messages)
raise_config_error 'Host does not support SSL'
end

def gets
def irc_gets
irc.gets
end

def eof?
def irc_eof?
irc.eof?
end

def puts(*args)
def irc_puts(*args)
irc.puts *args
end

Expand Down Expand Up @@ -125,7 +126,7 @@ def format_commit_message(commit)
"\002#{sha1[0..6]}\002 (#{files.size} files in #{dirs.size} dirs): #{short}"
end
end

def branch_name_matches?
return true if data['branch_regexes'].nil?
return true if data['branch_regexes'].strip == ""
Expand Down
16 changes: 8 additions & 8 deletions test/irc_test.rb
Expand Up @@ -11,15 +11,15 @@ def writable_io
@writable_io ||= StringIO.new
end

def puts(*args)
def irc_puts(*args)
writable_io.puts *args
end

def gets
def irc_gets
readable_io.gets
end

def eof?
def irc_eof?
true
end

Expand All @@ -44,10 +44,10 @@ def test_push
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end

def test_push_with_empty_branch_regex
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => ''}, payload)

svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
Expand All @@ -61,7 +61,7 @@ def test_push_with_empty_branch_regex
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end

def test_push_with_single_matching_branch_regex
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => 'mast*'}, payload)

Expand All @@ -78,15 +78,15 @@ def test_push_with_single_matching_branch_regex
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end

def test_push_with_single_mismatching_branch_regex
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => '^ticket*'}, payload)

svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_nil msgs.shift
end

def test_push_with_multiple_branch_regexes_where_all_match
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => 'mast*,^ticket*'}, payload)

Expand Down

0 comments on commit f910c50

Please sign in to comment.