Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some reworkings to make notifiers easier to use.

  • Loading branch information...
commit 72e0e0132edc3832092553e958fd3a93a2ad392a 1 parent d4556ac
Travis Reeder treeder authored
24 README.markdown → README.md
View
@@ -19,12 +19,11 @@ Get it running locally first, here's an example:
worker.test_config = @test_config
worker.run_local
-Add notifier
+Add built in notifier:
- worker.add_notifier("HipchatNotifier",{"hipchat_api_key"=>'secret_api_key',"room_name"=>'Room Name',"title"=>"From"})
-and/or
- worker.add_notifier("WebHookNotifier",{"url"=>'notification_url'})
-you could add as many notifiers as you need
+ worker.add_notifier(:hip_chat_notifier, :config=>{"hipchat_api_key"=>'secret_api_key', "room_name"=>'Room Name', "user_name"=>"AbtWorker"})
+
+you can add as many notifiers as you need and even make your own (read down for how to build custom notifiers).
Then try queuing it up.
@@ -40,14 +39,14 @@ Schedule it to run regularly to ensure you're always being covered.
## Custom notifiers
-###All you need:
+Here's how to build your own notifiers.
-* Implement in your notifier following methods:
+* Implement in your notifier the following methods:
setup configuration:
- def initialize(notifier_details)
- @url = notifier_details["url"]
+ def initialize(config)
+ @url = config["url"]
end
process simple text message
@@ -56,13 +55,12 @@ process simple text message
puts message
end
-if you need you could process more detailed results, 'result' is an instance of Test::Unit::TestResult
+if you want more detailed results, 'result' is an instance of Test::Unit::TestResult
def send_formatted_message(result)
result.inspect
end
+Then to use it:
-* Add your custom notifier into 'notifiers' folder or just merge it
-* Add your notifier to worker
- worker.add_notifier("YourCustomNotifierClass",{"option_name"=>'option_value'})
+ worker.add_notifier(File.join(File.dirname(__FILE__), 'console_notifier'), :class_name=>'ConsoleNotifier', :config={})
4 Rakefile
View
@@ -11,9 +11,9 @@ Jeweler::Tasks.new do |gemspec|
gemspec.authors = ["Travis Reeder"]
gemspec.files = FileList['lib/**/*.rb', 'VERSION.yml']
gemspec.add_dependency 'git'
+ gemspec.add_dependency 'minitest'
+ gemspec.add_dependency 'test-unit'
gemspec.add_dependency 'iron_worker'
- # gemspec.add_dependency 'rest-client'
- #gemspec.add_dependency 'typhoeus'
gemspec.required_ruby_version = '>= 1.9'
end
Jeweler::GemcutterTasks.new
4 abt.gemspec
View
@@ -13,13 +13,13 @@ Gem::Specification.new do |s|
s.description = "Always Be Testing Yo! A testing framework that runs on IronWorker http://www.iron.io"
s.email = "travis@iron.io"
s.extra_rdoc_files = [
- "README.markdown"
+ "README.md"
]
s.files = [
"VERSION.yml",
"lib/abt.rb",
"lib/abt/abt_worker.rb",
- "lib/abt/notifiers/hipchat_notifier.rb",
+ "lib/abt/notifiers/hip_chat_notifier.rb",
"lib/abt/notifiers/web_hook_notifier.rb",
"lib/abt/test_collector.rb"
]
112 lib/abt/abt_worker.rb
View
@@ -1,53 +1,49 @@
require 'iron_worker'
require 'json'
-# bump.....
-ARGV=[]
+
+# bump.
+ARGV=[] # this needs to stay here or else it won't run the correct tests
module Abt
- #
- #class MiniTestWithHooks < MiniTest::Unit
- # def before_suites
- # end
- #
- # def after_suites
- # end
- #
- # def _run_suites(suites, type)
- # puts 'run_suites ' + suites.inspect + ' type=' + type.inspect
- # begin
- # before_suites
- # super(suites, type)
- # ensure
- # after_suites
- # end
- # end
- #
- #
- #
- # def _run_suite(suite, type)
- # puts 'run_suite ' + suite.inspect + ' type=' + type.inspect
- # begin
- # # suite.before_suite
- # super(suite, type)
- # ensure
- # # suite.after_suite
- # end
- # end
- #end
- #
- #..
+
+ @@notifiers = {}
+ @@notifiers[:hip_chat_notifier] = {:file=>'notifiers/hip_chat_notifier', :class_name=>'HipChatNotifier'}
+
+ def self.notifiers
+ @@notifiers
+ end
+
class AbtWorker < IronWorker::Base
merge_gem 'minitest', :require=>['minitest/unit', 'minitest/autorun']
merge_gem 'test-unit', :require=>['test/unit/priority', 'test/unit/testcase', 'test/unit/assertions', 'test/unit']
merge_gem 'git'
- merge_gem 'hipchat-api'
merge_gem 'bundler'
merge 'test_collector'
- merge_folder 'notifiers'
+ #merge_folder 'notifiers'
attr_accessor :git_url, :test_config, :notifiers, :notify_every
- def add_notifier(notifier_name, notifier_details={})
- @notifiers||=[]
- @notifiers<<{"notifier_name"=>notifier_name, "notifier_details"=>notifier_details}
+ def initialize
+ @notifiers = []
+ end
+
+ def add_notifier(notifier_class, notifier_details={})
+ p notifier_class
+ p notifier_details
+ notifier_entry = {}
+ if notifier_class.instance_of?(Symbol)
+ p Abt.notifiers
+ n = Abt.notifiers[notifier_class]
+ puts "n=" + n.inspect
+ raise "Notifier not found: #{notifier_class}" if n.nil?
+ self.class.merge n[:file]
+ notifier_entry["class_name"] = n[:class_name]
+ notifier_entry["config"] = notifier_details[:config]
+ else
+ self.class.merge notifier_class
+ raise "Must include :class option" if notifier_details[:class_name].nil?
+ notifier_entry["class_name"] = notifier_details[:class_name]
+ notifier_entry["config"] = notifier_details[:config]
+ end
+ @notifiers << notifier_entry
end
def run
@@ -59,9 +55,6 @@ def run
require File.join(File.dirname(__FILE__), '/gems/test-unit/lib/test/unit')
require File.join(File.dirname(__FILE__), '/gems/minitest/lib/minitest/autorun')
end
- # Test::Unit.run = false
- #MiniTest::Unit.runner = MiniTestWithHooks.new
- # g = Git.open(user_dir, :log => Logger.new(STDOUT))
clone_dir = 'cloned'
x = File.join(user_dir, clone_dir)
p x
@@ -97,10 +90,12 @@ def run
if notifiers
notifiers.each do |notifier|
puts "NOTIFIER:#{notifier.inspect}"
- Test::Unit::Notify::Notifier.add_notifier(Kernel.const_get(notifier["notifier_name"]).new(notifier["notifier_details"]))
+ Test::Unit::Notify::Notifier.add_notifier(Kernel.const_get(notifier["class_name"]).new(notifier["config"]))
end
end
+ puts 'Starting autorunner'
Test::Unit::AutoRunner.run
+ puts 'Autorunner finished'
if old_specs
Gem.loaded_specs.clear
@@ -112,36 +107,7 @@ def run
end
end
- # ...
- # def suite_results_output(options={})
- # line_break = "\n"
- # if options[:format] == 'html'
- # line_break = "<br/>"
- # end
- # s = "Suite Results:#{line_break}"
- # s << "#{@num_failed} failed out of #{@num_tests} tests.#{line_break}"
- # if @num_failed > 0
- # @failed.each do |f|
- # s << "#{f.test_class}.#{f.test_method} failed: #{f.result.message}#{line_break}"
- # end
- # end
- # s << "Test suite duration: #{duration}ms.#{line_break}"
- # s
- # end
- #
- # def duration
- # ((@end_time.to_f - @start_time.to_f) * 1000.0).to_i
- # end
- #
- # def time_in_ms(t)
- # (t.to_f * 1000.0).to_i
- # end
- #
- # # callbacks
- # def on_complete
- #
- # end
- #
+
end
end
15 lib/abt/notifiers/hipchat_notifier.rb → lib/abt/notifiers/hip_chat_notifier.rb
View
@@ -1,10 +1,11 @@
-class HipchatNotifier
+class HipChatNotifier
+ IronWorker.config.merge_gem 'hipchat-api'
require 'hipchat-api'
- def initialize(notifier_details)
- @client = HipChat::API.new(notifier_details["hipchat_api_key"])
- @room_name = notifier_details["room_name"]
- @title= notifier_details["title"]
+ def initialize(config)
+ @client = HipChat::API.new(config["token"])
+ @room_name = config["room_name"]
+ @user_name = config["user_name"] || "AbtWorker"
end
def send_formatted_message(result)
@@ -21,9 +22,9 @@ def send_formatted_message(result)
def send_message(message,color='yellow')
puts "sending_message #{message}"
begin
- puts @client.rooms_message(@room_name, @title, message, false,color).body
+ puts @client.rooms_message(@room_name, @user_name, message, false,color).body
rescue =>ex
ex.inspect
end
end
-end
+end
2  lib/abt/test_collector.rb
View
@@ -35,7 +35,7 @@ def self.get_params
def self.add_notifier(sender)
@senders||=[]
@senders<<sender
- puts "adding sender!#{@senders.inspect}"
+ puts "adding sender! #{@senders.inspect}"
end
def self.get_notifiers
11 test/console_notifier.rb
View
@@ -0,0 +1,11 @@
+class ConsoleNotifier
+
+ def initialize(notifier_details)
+
+ end
+
+ def send_message(message)
+ puts 'CONSOLE RESULTS: ' + message
+ end
+
+end
8 test/sw_test.rb
View
@@ -13,10 +13,12 @@
worker = Abt::AbtWorker.new
worker.git_url = "git://github.com/iron-io/iron_mq_ruby.git"
worker.test_config = @test_config
-worker.add_notifier("HipchatNotifier",{"hipchat_api_key"=>'api_key',"room_name"=>'room_name'})
-worker.add_notifier("WebHookNotifier","url"=>"http://www.someurl.com")
+worker.add_notifier(:hip_chat_notifier, :config=>{"token"=>@config["hip_chat"]["token"], "room_name"=>@config["hip_chat"]['room_name']})
+worker.add_notifier(File.join(File.dirname(__FILE__), 'console_notifier'), :class_name=>'ConsoleNotifier')
+#worker.add_notifier("WebHookNotifier", "url"=>"http://www.someurl.com")
#worker.run_local
worker.queue
-worker.wait_until_complete
+status = worker.wait_until_complete
+p status
puts "LOG:"
puts worker.get_log
Please sign in to comment.
Something went wrong with that request. Please try again.