Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rafmagana committed Jul 23, 2010
1 parent 54fac4d commit bb2d8df
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 5 deletions.
15 changes: 14 additions & 1 deletion test/helper.rb
@@ -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
6 changes: 6 additions & 0 deletions test/suite.rb
@@ -0,0 +1,6 @@
require 'helper'

tests = Dir["#{File.dirname(__FILE__)}/test_*.rb"]
tests.each do |file|
require file
end
51 changes: 51 additions & 0 deletions test/test_notification.rb
@@ -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
22 changes: 22 additions & 0 deletions test/test_priority.rb
@@ -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
15 changes: 11 additions & 4 deletions test/test_prowly.rb
@@ -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.