Skip to content
Browse files

test xmpp notifier

  • Loading branch information...
1 parent 126e0d5 commit 6a664fa7e711b29b6ce8a4ecd84ef337345846ed @flyerhzm committed
View
2 Gemfile.lock
@@ -16,6 +16,7 @@ GEM
diff-lcs (~> 1.1.2)
rspec-mocks (2.1.0)
ruby-growl (3.0)
+ xmpp4r (0.5)
PLATFORMS
ruby
@@ -24,3 +25,4 @@ DEPENDENCIES
rspec
ruby-growl
uniform_notifier!
+ xmpp4r
View
2 lib/uniform_notifier.rb
@@ -16,7 +16,7 @@ def growl=(growl)
end
def xmpp=(xmpp)
- UniformNotifier::Growl.setup_connection(xmpp)
+ UniformNotifier::Xmpp.setup_connection(xmpp)
end
end
end
View
2 lib/uniform_notifier/growl.rb
@@ -19,7 +19,7 @@ def self.setup_connection( growl )
notify 'Uniform Notifier Growl has been turned on'
rescue LoadError
@growl = nil
- raise NotificationError.new( 'You must install the ruby-growl gem to use Growl notifications: `gem install ruby-growl`' )
+ raise NotificationError.new( 'You must install the ruby-growl gem to use Growl notification: `gem install ruby-growl`' )
end
private
View
16 lib/uniform_notifier/xmpp.rb
@@ -8,9 +8,9 @@ def self.active?
@xmpp
end
- def self.out_of_channel_notify( notice )
+ def self.out_of_channel_notify( message )
return unless active?
- notify( notice.standard_notice )
+ notify( message )
end
def self.setup_connection( xmpp_information )
@@ -22,9 +22,9 @@ def self.setup_connection( xmpp_information )
@show_online_status = xmpp_information[:show_online_status]
connect
- rescue MissingSourceFile
+ rescue LoadError
@xmpp = nil
- raise NotificationError.new( 'You must install the xmpp4r gem to use XMPP notifications: `gem install xmpp4r`' )
+ raise NotificationError.new( 'You must install the xmpp4r gem to use XMPP notification: `gem install xmpp4r`' )
end
private
@@ -39,16 +39,12 @@ def self.connect
def self.notify( message )
message = Jabber::Message.new( @receiver, message ).
set_type( :normal ).
- set_id( '1' ).
- set_subject( 'Bullet Notification' )
+ set_subject( 'Uniform Notifier' )
@xmpp.send( message )
end
def self.presence_status
- project_name = Rails.root.basename.to_s.camelcase
- time = Time.now
-
- Jabber::Presence.new.set_status( "Bullet in project '#{project_name}' started on #{time}" )
+ Jabber::Presence.new.set_status( "Uniform Notifier started on #{Time.now}" )
end
end
end
View
48 spec/uniform_notifier/xmpp_spec.rb
@@ -0,0 +1,48 @@
+require 'spec_helper'
+require 'xmpp4r'
+
+describe UniformNotifier::Xmpp do
+
+ it "should notify xmpp without online status" do
+ jid = double("jid")
+ xmpp = double("xmpp")
+ Jabber::JID.should_receive(:new).with('from@gmail.com').and_return(jid)
+ Jabber::Client.should_receive(:new).with(jid).and_return(xmpp)
+ xmpp.should_receive(:connect)
+ xmpp.should_receive(:auth).with('123456')
+
+ message = double("message")
+ Jabber::Message.should_receive(:new).with('to@gmail.com', 'notify xmpp').and_return(message)
+ message.should_receive(:set_type).with(:normal).and_return(message)
+ message.should_receive(:set_subject).with('Uniform Notifier').and_return(message)
+ xmpp.should_receive(:send).with(message)
+
+ UniformNotifier.xmpp = {:account => 'from@gmail.com', :password => '123456', :receiver => 'to@gmail.com', :show_online_status => false}
+ UniformNotifier::Xmpp.out_of_channel_notify('notify xmpp')
+ end
+
+ it "should notify xmpp with online status" do
+ jid = double("jid")
+ xmpp = double("xmpp")
+ Jabber::JID.should_receive(:new).with('from@gmail.com').and_return(jid)
+ Jabber::Client.should_receive(:new).with(jid).and_return(xmpp)
+ xmpp.should_receive(:connect)
+ xmpp.should_receive(:auth).with('123456')
+
+ presence = double("presence")
+ now = Time.now
+ Time.stub!(:now).and_return(now)
+ Jabber::Presence.should_receive(:new).and_return(presence)
+ presence.should_receive(:set_status).with("Uniform Notifier started on #{now}").and_return(presence)
+ xmpp.should_receive(:send).with(presence)
+
+ message = double("message")
+ Jabber::Message.should_receive(:new).with('to@gmail.com', 'notify xmpp').and_return(message)
+ message.should_receive(:set_type).with(:normal).and_return(message)
+ message.should_receive(:set_subject).with('Uniform Notifier').and_return(message)
+ xmpp.should_receive(:send).with(message)
+
+ UniformNotifier.xmpp = {:account => 'from@gmail.com', :password => '123456', :receiver => 'to@gmail.com', :show_online_status => true}
+ UniformNotifier::Xmpp.out_of_channel_notify('notify xmpp')
+ end
+end
View
3 uniform_notifier.gemspec
@@ -13,9 +13,10 @@ Gem::Specification.new do |s|
s.description = %q{TODO: Write a gem description}
s.rubyforge_project = "uniform_notifier"
-
+
s.add_development_dependency "rspec"
s.add_development_dependency "ruby-growl"
+ s.add_development_dependency "xmpp4r"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")

0 comments on commit 6a664fa

Please sign in to comment.
Something went wrong with that request. Please try again.