Permalink
Browse files

added tests

  • Loading branch information...
1 parent 54fac4d commit bb2d8df3ba2a2398386bf36521d9dcd079f48116 @rafmagana committed Jul 23, 2010
Showing with 104 additions and 5 deletions.
  1. +14 −1 test/helper.rb
  2. +6 −0 test/suite.rb
  3. +51 −0 test/test_notification.rb
  4. +22 −0 test/test_priority.rb
  5. +11 −4 test/test_prowly.rb
View
@@ -1,10 +1,23 @@
require 'rubygems'
require 'test/unit'
+require 'mocha'
require 'shoulda'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'prowly'
class Test::Unit::TestCase
-end
+ def apikey
+ "f" * 40
+ end
+
+ def apikeys
+ [apikey] * 6
+ end
+
+ def valid_params?(params)
+ array_of_params = params.split("&")
+ array_of_params.each { |param, value| }
+ end
+end
View
@@ -0,0 +1,6 @@
+require 'helper'
+
+tests = Dir["#{File.dirname(__FILE__)}/test_*.rb"]
+tests.each do |file|
+ require file
+end
View
@@ -0,0 +1,51 @@
+require 'helper'
+
+class TestNotification < Test::Unit::TestCase
+
+ context "A Notification" do
+
+ should "accept one apikey" do
+ notification = Prowly::Notification.new(:apikey => apikey)
+
+ assert_equal notification.apikey, apikey
+ end
+
+ should "accept an array of apikeys and turn it into a comma-separated keys" do
+ notification = Prowly::Notification.new(:apikeys => apikeys)
+
+ assert_equal notification.apikeys, apikeys.join(",")
+ end
+
+ should "raise an exception if apikey and apikeys are set at the same time" do
+ assert_raises Prowly::Notification::DuplicatedAssignmentOfApiKey do
+ notification = Prowly::Notification.new(:apikeys => apikeys, :apikey => apikey)
+ end
+ end
+
+ should "set default parameters" do
+ notification = Prowly::Notification.new(:apikey => apikey)
+ assert_equal notification.application, "Prowly"
+ assert_equal notification.event, "Prowly is working!!"
+ assert_equal notification.description, "This is the default description"
+ assert_equal notification.priority, Prowly::Notification::Priority::NORMAL
+ end
+
+ context "#to_params method" do
+ should "return a string separated by &s" do
+ notif_with_apikey = Prowly::Notification.new(:apikey => apikey, :application => "test", :description => "desc")
+ notif_with_apikeys = Prowly::Notification.new(:apikeys => apikeys, :application => "test", :description => "desc")
+
+ #check if the param were built the right way
+ end
+
+ should "raise and exception if no apikey was given" do
+ end
+
+ should "raise and exception if no application name was given" do
+ end
+
+ should "raise and exception if no description given was given" do
+ end
+ end
+ end
+end
View
@@ -0,0 +1,22 @@
+require 'helper'
+
+class TestPriority < Test::Unit::TestCase
+
+ context "Priority module" do
+ should "raise an exception if priority is not available" do
+ assert_raises Prowly::Notification::PriorityNotAvailable do
+ Prowly::Notification::Priority::NONEXISTENT_PRIORITY
+ end
+ end
+
+ should "return numeric values for each priority" do
+ Priority = Prowly::Notification::Priority
+
+ assert_equal Priority::VERY_LOW, -2
+ assert_equal Priority::MODERATE, -1
+ assert_equal Priority::NORMAL, 0
+ assert_equal Priority::HIGH, 1
+ assert_equal Priority::EMERGENCY, 2
+ end
+ end
+end
View
@@ -1,7 +1,14 @@
require 'helper'
class TestProwly < Test::Unit::TestCase
- should "probably rename this file and start testing for real" do
- flunk "hey buddy, you should probably rename this file and start testing for real"
- end
-end
+ context "Prowly notification" do
+ should "verify the key" do
+ #response_mock = mock('Prowly::Response')
+ #response_mock.expects(:succeeded?).returns(false).once
+
+ #Prowly::Interface.instance.expects(:call).returns(response_mock).once
+
+ #assert Prowly.valid_key?(apikey)
+ end
+ end
+end

0 comments on commit bb2d8df

Please sign in to comment.