From 988f4a83baa35e706fd423895e0106b0d99fc428 Mon Sep 17 00:00:00 2001 From: Francisco Marcelo de Araújo Lima Júnior Date: Mon, 19 May 2014 18:44:34 -0300 Subject: [PATCH] #community dashboard - add unit test --- plugins/community_hub/test/unit/community_hub_plugin/listener_test.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+), 0 deletions(-) create mode 100644 plugins/community_hub/test/unit/community_hub_plugin/listener_test.rb diff --git a/plugins/community_hub/test/unit/community_hub_plugin/listener_test.rb b/plugins/community_hub/test/unit/community_hub_plugin/listener_test.rb new file mode 100644 index 0000000..565b8bf --- /dev/null +++ b/plugins/community_hub/test/unit/community_hub_plugin/listener_test.rb @@ -0,0 +1,31 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class ListenerTest < ActiveSupport::TestCase + + should 'initialize logger' do + logger = CommunityHubPlugin::Listener.initialize_logger + logfile = logger.instance_variable_get(:@logdev).instance_variable_get(:@filename) + assert_instance_of(Logger, logger) + assert File.exists?(logfile) + end + + should 'log message' do + logdir = File.join(RAILS_ROOT, 'log', CommunityHubPlugin::Listener.name.underscore) + + if File.exists?(logdir) + Dir.foreach(logdir) { |f| + fn = File.join(logdir, f); + File.delete(fn) if f != '.' && f != '..' + } + end + + logger = CommunityHubPlugin::Listener.initialize_logger + CommunityHubPlugin::Listener.log('testmessage') + + logfile = logger.instance_variable_get(:@logdev).instance_variable_get(:@filename) + text = File.open(logfile).read + + assert_match /testmessage/, text + end + +end -- libgit2 0.21.2