Permalink
Browse files

Use Integrity::Notifier::Test; fix use of deprecated methods

  • Loading branch information...
1 parent 0562a7e commit 691e2c9c98a6ff057487d6b96a2a861ed8afcafb @sr sr committed Apr 13, 2009
Showing with 57 additions and 25 deletions.
  1. +4 −4 lib/notifier/campfire.rb
  2. +34 −15 test/campfire_test.rb
  3. +19 −6 test/helper.rb
View
@@ -28,14 +28,14 @@ def room
end
def short_message
- "Build #{commit.short_commit_identifier} of #{commit.project.name} #{commit.successful? ? "was successful" : "failed"}"
+ "Build #{commit.short_identifier} of #{commit.project.name} #{commit.successful? ? "was successful" : "failed"}"
end
def full_message
<<-EOM
-Commit Message: #{commit.commit_message}
-Commit Date: #{commit.commited_at}
-Commit Author: #{commit.commit_author.name}
+Commit Message: #{commit.message}
+Commit Date: #{commit.committed_at}
+Commit Author: #{commit.author.name}
#{stripped_build_output}
EOM
View
@@ -2,30 +2,49 @@
context "The Campfire notifier" do
setup do
- @config = {}
+ setup_database
+
+ @config = { "account" => "integrity",
+ "use_ssl" => false,
+ "room" => "ci",
+ "user" => "foo",
+ "pass" => "bar" }
@notifier = Integrity::Notifier::Campfire
+ @room = stub(:speak => nil, :paste => nil)
end
- test "alerts Campfire on build" do
- @notifier.any_instance.expects(:room).at_least_once.returns mock(:speak => true)
- @notifier.any_instance.expects(:short_message).returns('')
- @notifier.any_instance.expects(:commit_url).returns('')
- @notifier.notify_of_build(stub_everything(:failed? => false, :project => stub_everything), @config)
+ def notifier
+ "Campfire"
end
- test "sends the full message on failure only" do
- @notifier.any_instance.expects(:room).at_least_once.returns mock(:speak => true, :paste => true)
+ test "configuration form" do
+ assert_form_have_option "account", @config["account"]
+ assert_form_have_option "use_ssl", @config["use_ssl"]
+ assert_form_have_option "room", @config["room"]
+ assert_form_have_option "user", @config["user"]
+ assert_form_have_option "pass", @config["pass"]
+ end
- @notifier.any_instance.expects(:full_message).returns('')
- @notifier.any_instance.expects(:short_message).returns('')
- @notifier.any_instance.expects(:commit_url).returns('')
+ test "successful build" do
+ build = Integrity::Build.gen(:successful)
- @notifier.notify_of_build(stub_everything(:failed? => true, :project => stub_everything), @config)
+ @notifier.any_instance.stubs(:room).at_least_once.returns(@room)
+ @room.expects(:speak).with { |value| value.include?(build.commit.identifier) }
+ @room.expects(:paste).never
+ @notifier.notify_of_build(build, @config)
end
- test "renders a haml config file" do
- haml = Integrity::Notifier::Campfire.to_haml
- assert haml.include?('campfire_notifier_account')
+ test "failed build" do
+ build = Integrity::Build.gen(:failed)
+
+ @notifier.any_instance.stubs(:room).at_least_once.returns(@room)
+ @room.expects(:speak).with { |value| value.include?(build.commit.identifier) }
+ @room.expects(:paste).with { |value|
+ value.include?(build.commit.message) &&
+ value.include?(build.output)
+ }
+
+ @notifier.notify_of_build(build, @config)
end
end
View
@@ -1,3 +1,22 @@
+require 'rubygems'
+require 'mocha'
+require 'integrity/notifier/test'
+require 'redgreen'
+
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
+require 'notifier/campfire'
+
+class Test::Unit::TestCase
+ include Integrity::Notifier::Test
+end
+
+# NOTE: Because of a bug in integrity/notifier/test/fixtures
+class Array
+ def pick
+ slice(Kernel.rand(size))
+ end
+end
+
##
# test/spec/mini 2
# http://gist.github.com/25455
@@ -16,9 +35,3 @@ def self.teardown(&block) define_method(:teardown, &block) end
end
klass.class_eval &block
end
-
-require 'rubygems'
-require 'mocha'
-require 'redgreen'
-$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
-require 'notifier/campfire'

0 comments on commit 691e2c9

Please sign in to comment.