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

Commit

Permalink
Add branch regex filter for IRC client
Browse files Browse the repository at this point in the history
Add tests for regex filter for IRC client.
Fix edge case of existing, but empty regex filter.
  • Loading branch information
Jeff Weiss committed Apr 11, 2012
1 parent 5dfdb9d commit 59bec11
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions services/irc.rb
Expand Up @@ -121,6 +121,7 @@ def format_commit_message(commit)

def branch_name_matches?
return true if data['branch_regexes'].nil?
return true if data['branch_regexes'].strip == ""
branch_regexes = data['branch_regexes'].split(',')
branch_regexes.each do |regex|
return true if Regexp.new(regex) =~ branch_name
Expand Down
84 changes: 84 additions & 0 deletions test/irc_test.rb
Expand Up @@ -44,6 +44,90 @@ 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
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
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)

svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
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)

svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end

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

svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end

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

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

def test_push_with_nickserv
svc = service({'room' => 'r', 'nick' => 'n', 'nickservidentify' => 'booya'},
Expand Down

0 comments on commit 59bec11

Please sign in to comment.