Нет описания http://j1x-huginn.herokuapp.com

growl_agent_spec.rb 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. require 'spec_helper'
  2. describe Agents::GrowlAgent do
  3. before do
  4. @checker = Agents::GrowlAgent.new(:name => 'a growl agent',
  5. :options => { :growlserver => 'localhost',
  6. :growlappname => 'HuginnGrowlApp',
  7. :growlnotificationname => 'Notification',
  8. :expected_receive_period_in_days => '1' })
  9. @checker.user = users(:bob)
  10. @checker.save!
  11. class Agents::GrowlAgent #this should really be done with RSpec-Mocks
  12. def notify_growl(message,subject)
  13. end
  14. end
  15. @event = Event.new
  16. @event.agent = agents(:bob_weather_agent)
  17. @event.payload = { :subject => 'Weather Alert!', :message => 'Looks like its going to rain' }
  18. @event.save!
  19. end
  20. describe "#working?" do
  21. it "checks if events have been received within the expected receive period" do
  22. @checker.should_not be_working # No events received
  23. Agents::GrowlAgent.async_receive @checker.id, [@event.id]
  24. @checker.reload.should be_working # Just received events
  25. two_days_from_now = 2.days.from_now
  26. stub(Time).now { two_days_from_now }
  27. @checker.reload.should_not be_working # More time has passed than the expected receive period without any new events
  28. end
  29. end
  30. describe "validation" do
  31. before do
  32. @checker.should be_valid
  33. end
  34. it "should validate presence of of growlserver" do
  35. @checker.options[:growlserver] = ""
  36. @checker.should_not be_valid
  37. end
  38. it "should validate presence of expected_receive_period_in_days" do
  39. @checker.options[:expected_receive_period_in_days] = ""
  40. @checker.should_not be_valid
  41. end
  42. end
  43. end