Permalink
Browse files

Migrated tests to RSpec.

  • Loading branch information...
1 parent d51a974 commit e9bed74c5de6a6b2465bac6a47dfa9586b3f3f7b @fnando committed Sep 20, 2012
Showing with 88 additions and 89 deletions.
  1. +1 −0 .rspec
  2. +2 −2 lib/notifier/version.rb
  3. +72 −0 spec/notifier_spec.rb
  4. +13 −0 spec/spec_helper.rb
  5. +0 −73 test/notifier_test.rb
  6. +0 −14 test/test_helper.rb
View
1 .rspec
@@ -0,0 +1 @@
+--color --format documentation
View
4 lib/notifier/version.rb
@@ -1,8 +1,8 @@
module Notifier
module Version
MAJOR = 0
- MINOR = 2
- PATCH = 1
+ MINOR = 3
+ PATCH = 0
STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
end
end
View
72 spec/notifier_spec.rb
@@ -0,0 +1,72 @@
+require "spec_helper"
+
+describe Notifier do
+ before do
+ unsupport_all_notifiers
+ Notifier.default_notifier = nil
+ end
+
+ it "retrieves list of supported notifiers" do
+ Notifier::Snarl.stub :supported? => true
+ Notifier::Knotify.stub :supported? => true
+
+ expect(Notifier.supported_notifiers.size).to eql(3)
+ end
+
+ it "returns first available notifier" do
+ Notifier::Snarl.stub :supported? => true
+ Notifier::Knotify.stub :supported? => true
+
+ expect(Notifier.notifier).to eql(Notifier::Snarl)
+ end
+
+ it "prefers default notifier" do
+ Notifier::Snarl.stub :supported? => true
+ Notifier::Knotify.stub :supported? => true
+
+ Notifier.default_notifier = :knotify
+
+ expect(Notifier.notifier).to eql(Notifier::Knotify)
+ end
+
+ it "sends notification" do
+ params = {
+ :title => "Some title",
+ :message => "Some message",
+ :image => "image.png"
+ }
+
+ Notifier::Snarl.stub :supported? => true
+ Notifier::Snarl.should_receive(:notify).with(params)
+
+ Notifier.notify(params)
+ end
+
+ it "retrieves list of all notifiers" do
+ expect(Notifier.notifiers.size).to eql(8)
+ end
+
+ it "considers Placebo as fallback notifier" do
+ expect(Notifier.supported_notifiers.last).to eql(Notifier::Placebo)
+ end
+
+ it "returns notifier by its name" do
+ expect(Notifier.from_name(:osd_cat)).to eql(Notifier::OsdCat)
+ expect(Notifier.from_name(:notify_send)).to eql(Notifier::NotifySend)
+ expect(Notifier.from_name(:growl)).to eql(Notifier::Growl)
+ end
+
+ it "returns notifier by its name when supported" do
+ Notifier::Snarl.stub :supported? => true
+ expect(Notifier.supported_notifier_from_name(:snarl)).to eql(Notifier::Snarl)
+ end
+
+ it "returns nil when have no supported notifiers" do
+ expect(Notifier.supported_notifier_from_name(:snarl)).to be_nil
+ end
+
+ it "returns nil when an invalid notifier name is provided" do
+ expect(Notifier.from_name(:invalid)).to be_nil
+ expect(Notifier.supported_notifier_from_name(:invalid)).to be_nil
+ end
+end
View
13 spec/spec_helper.rb
@@ -0,0 +1,13 @@
+require "notifier"
+
+module SpecHelpers
+ def unsupport_all_notifiers
+ Notifier.notifiers.each do |notifier|
+ notifier.stub :supported? => false unless notifier == Notifier::Placebo
+ end
+ end
+end
+
+RSpec.configure do |config|
+ config.include SpecHelpers
+end
View
73 test/notifier_test.rb
@@ -1,73 +0,0 @@
-require "test_helper"
-
-class NotifierTest < Test::Unit::TestCase
- def setup
- unsupport_all_notifiers
- Notifier.default_notifier = nil
- end
-
- test "retrieve list of supported notifiers" do
- Notifier::Snarl.expects(:supported?).returns(true)
- Notifier::Knotify.expects(:supported?).returns(true)
-
- assert_equal 3, Notifier.supported_notifiers.size
- end
-
- test "return first available notifier" do
- Notifier::Snarl.expects(:supported?).returns(true)
- Notifier::Knotify.expects(:supported?).returns(true)
-
- assert_equal Notifier::Snarl, Notifier.notifier
- end
-
- test "prefer default notifier" do
- Notifier::Snarl.stubs(:supported?).returns(true)
- Notifier::Knotify.expects(:supported?).returns(true)
-
- Notifier.default_notifier = :knotify
-
- assert_equal Notifier::Knotify, Notifier.notifier
- end
-
- test "send notification" do
- params = {
- :title => "Some title",
- :message => "Some message",
- :image => "image.png"
- }
-
- Notifier::Snarl.expects(:supported?).returns(true)
- Notifier::Snarl.expects(:notify).with(params)
-
- Notifier.notify(params)
- end
-
- test "retrieve list of all notifiers" do
- assert_equal 8, Notifier.notifiers.size
- end
-
- test "consider Placebo as fallback notifier" do
- assert_equal Notifier::Placebo, Notifier.supported_notifiers.last
- end
-
- test "return notifier by its name" do
- assert_equal Notifier::OsdCat, Notifier.from_name(:osd_cat)
- assert_equal Notifier::NotifySend, Notifier.from_name(:notify_send)
- assert_equal Notifier::Growl, Notifier.from_name(:growl)
- end
-
- test "return notifier by its name when supported" do
- Notifier::Snarl.expects(:supported?).returns(true)
-
- assert_equal Notifier::Snarl, Notifier.supported_notifier_from_name(:snarl)
- end
-
- test "return nil when have no supported notifiers" do
- assert_nil Notifier.supported_notifier_from_name(:snarl)
- end
-
- test "return nil when an invalid notifier name is provided" do
- assert_nil Notifier.from_name(:invalid)
- assert_nil Notifier.supported_notifier_from_name(:invalid)
- end
-end
View
14 test/test_helper.rb
@@ -1,14 +0,0 @@
-gem "test-unit"
-require "test/unit"
-require "mocha"
-
-require "notifier"
-
-class Test::Unit::TestCase
- private
- def unsupport_all_notifiers
- Notifier.notifiers.each do |notifier|
- notifier.stubs(:supported?).returns(false) unless notifier == Notifier::Placebo
- end
- end
-end

0 comments on commit e9bed74

Please sign in to comment.