Skip to content

Commit

Permalink
Passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaberer committed Jul 1, 2013
1 parent a39d734 commit 3dac695
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
nguage: ruby
language: ruby
rvm:
- ruby-head
- 1.9.2
- 1.9.3
4 changes: 3 additions & 1 deletion lib/cinch/plugins/hangouts/hangouts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Cinch::Plugins
class Hangouts
include Cinch::Plugin

attr_accessor :storage

self.help = "Use .hangouts to see the info for any recent hangouts. You can also use .hangouts subscribe to sign up for notifications."

match /hangouts\z/, method: :list_hangouts
Expand All @@ -20,7 +22,7 @@ class Hangouts
# https://plus.google.com/hangouts/_/fbae432b70a47bdf7786e53a16f364895c09d9f8
#
# The regex will need to be updated if the url scheme changes in the future.
HANGOUTS_REGEX = /plus.google.com\/hangouts\/_\/([^\/?]{40})/
HANGOUTS_REGEX = /plus.google.com\/hangouts\/_\/([a-f0-9]{40})/

def initialize(*args)
super
Expand Down
51 changes: 49 additions & 2 deletions spec/cinch-hangouts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,60 @@
describe Cinch::Plugins::Hangouts do
include Cinch::Test

before(:all) do
before(:each) do
@bot = make_bot(Cinch::Plugins::Hangouts, { :filename => '/dev/null',
:response_type => :channel })
end

it 'should return an errohangout links matching' do
it 'should return an error if no one has linked a hangout' do
msg = make_message(@bot, '!hangouts')
get_replies(msg).first.should == "No hangouts have been linked recently!"
end

it 'should not capture a malformed (invalid chars) Hangout link' do
msg = make_message(@bot, url_for_id('82b5cc7f76b7a%19c180416c2f509027!!d8856d'),
{ :channel => '#foo' })
get_replies(msg).should be_empty
msg = make_message(@bot, '!hangouts')
get_replies(msg).first.should == "No hangouts have been linked recently!"
end

it 'should not capture a malformed (wrong length) Hangout link' do
msg = make_message(@bot, url_for_id('82b5cc'),
{ :channel => '#foo' })
get_replies(msg).should be_empty
msg = make_message(@bot, '!hangouts')
get_replies(msg).first.should == "No hangouts have been linked recently!"
end

it 'should capture a legit Hangout link and store it in @storage' do
msg = make_message(@bot, url_for_id, { :channel => '#foo' })
get_replies(msg).should be_empty
msg = make_message(@bot, '!hangouts')
get_replies(msg).first.should_not == "No hangouts have been linked recently!"
end

it 'should capture a legit Hangout link and store it in @storage' do
msg = make_message(@bot, url_for_id, { :channel => '#foo' })
get_replies(msg).should be_empty
sleep 1 # hack until 'time-lord' fix gets released
msg = make_message(@bot, '!hangouts')
reply = get_replies(msg).last
reply.should include "test started a hangout at"
reply.should match(/it was last linked \d seconds? ago/)
end

it 'should capture a legit Hangout link f it has trailing params' do
msg = make_message(@bot, url_for_id('82b5cc7f76b7a1019c180416c2f509027bd8856d?pqs=1&authuser=0&hl=en'))
get_replies(msg, :channel)
sleep 1 # hack until 'time-lord' fix gets released
msg = make_message(@bot, '!hangouts')
reply = get_replies(msg).last
reply.should include "test started a hangout at"
reply.should match(/it was last linked \d seconds? ago/)
end

def url_for_id(id = '82b5cc7f76b7a1019c180416c2f509027bd8856d')
"https://plus.google.com/hangouts/_/#{id}"
end
end

0 comments on commit 3dac695

Please sign in to comment.